【问题标题】:How to add condition in ARM Bicep template?如何在 ARM Bicep 模板中添加条件?
【发布时间】:2021-04-13 14:51:33
【问题描述】:

假设,我只想在param isProduction bool 时部署一个单独的资源 是true。 二头肌可以吗?

我在文档中找不到这个。

【问题讨论】:

    标签: azure arm conditional-statements infrastructure-as-code azure-bicep


    【解决方案1】:

    除了已经给出的答案之外,不仅可以基于条件部署整个资源,还可以使用条件三元运算符针对特定环境更改资源的各个属性。以下是 Azure Front Door 的示例,其中仅在生产环境中使用高级层:

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

    【讨论】:

      【解决方案2】:

      if(isProduction)后面有一个语法if(isProduction),例如:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-10-12
        • 2021-04-18
        • 1970-01-01
        • 1970-01-01
        • 2014-05-10
        • 1970-01-01
        • 2023-01-11
        相关资源
        最近更新 更多