Nullable types in Bicep

Sometimes you need to define nullable parameters in Bicep files. It is possible by adding ? character after the type of the parameter:

param <param_name> <param_type>?

For example - let's assume the case that you need to deploy subnet and assign the NSG to it, but it happens conditionally. Then in Bicep module for subnet you could have

param nsgId string?

So if you have not deployed the NSG and you do not have the ID of NSG to push to the subnet, you can just skip it and accept null value.

This is the basic stuff, but I have not found it in the documentation, so I am adding it here. Here you can find other useful docs and blogposts about nullability in Bicep:

How do I create nullable params in Bicep?
In Bicep I have a module that defines an app service and sets the virtual network from a parameter like this: param vNetSubnetId string resource webApplication ‘Microsoft.Web/sites@2022-03-01’ = {…
Azure Bicep nullability operators explained
Operators are widely used in Azure Bicep. Commonly used operators include arithmetic operators like + and – for performing calculations, as well as comparison operators such as == and != and …
Bicep null-forgiving operator - Azure Resource Manager
Describes Bicep null-forgiving operator.
Bicep logical operators - Azure Resource Manager
Describes Bicep logical operators that evaluate conditions.
Bicep safe-dereference operator - Azure Resource Manager
Describes Bicep safe-dereference operator.

Read more