简体   繁体   中英

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.

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>...
}

In addition to the answer already given, not only can the whole resource be deployed based on a condition, but also individual properties of a resource can be changed for a specific environment using conditional ternary operator. The following is an example for Azure Front Door, where only in the production environment the Premium Tier is used:

resource profile 'Microsoft.Cdn/profiles@2020-09-01' = {
  name: 'azureFrontDoor'
  location: 'global'
  sku: {
    name: isProduction ? 'Premium_AzureFrontDoor' : 'Standard_AzureFrontDoor'
  }
  tags: tags
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM