在Azure ARM模板中使用条件 [英] Using conditions in Azure ARM templates

查看:82
本文介绍了在Azure ARM模板中使用条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以在模板中使用条件语句?

Is there any way to use conditional statements in templates?

例如,我正在构建模板,该模板将在质量检查和生产环境中具有带有数据磁盘的虚拟机,而在开发人员中没有数据磁盘.另一种情况是,有些扩展只需要安装在产品VM中,而无需安装在其他地方.

for example I am building template which will have vms with data disks on QA and Production, but no data disks on Dev. Another scenario would be there are some extensions only needs to be installed in prod VMs but no where else.

感谢您的帮助.

推荐答案

要实现这一目标的关键属性是:

The key properties to achieve this are:

  • templateLink设置要包含的模板以及要传递给被调用模板的参数的名称.

  • templateLink that sets the template to be included and the names of the parameters to be passed to the called template.

"templateLink": {
    "uri": "[variables('sharedTemplateUrl')]",
    "contentVersion": "1.0.0.0"
}

  • newOrExisting根据其值,我们可以决定使用质量检查还是产品配置.

  • newOrExisting based on its value we can decide to use an QA versus Productoin config.

    "newOrExisting": "new",
    
    "configHash": {
      "new": "[concat(parameters('templateBaseUrl'),'partials/QA.json')]",
      "existing": "[concat(parameters('templateBaseUrl'),'partials/Production.json')]"
    }
    
    "configTemplate": "[variables('configHash')[parameters('Settings').newOrExisting]]"
    

  • 您可能会看到

    You could see Azure ARM deployments: how to perform conditional deployments which has provided more details.

    这篇关于在Azure ARM模板中使用条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆