azureconditional-statementsazure-resource-managerazure-bicepinfrastructure-as-code

How to add condition in ARM Bicep template?


Let’s say, I want to deploy a separate resource only if param isProduction bool is true. Is that possible with Bicep?

I could not find this in the documentation.


Solution

  • There is a syntax if(isProduction) that can be used after =, for example:

    param isProduction bool
    
    resource prodWebApp 'Microsoft.Web/sites@2020-12-01' = if (isProduction) {
      name: 'MyWebApp'
      ...<other props>...
    }