ARM模板中是否可以有条件属性 [英] Is it possible to have conditional property in ARM template

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

问题描述

我知道可以为属性值提供条件输出,但是可以有条件属性本身.例如,我有创建 Microsoft.Compute/VirtualMachine 的模板,并且它是Windows和Linux的相同模板.但是对于Windows,我需要指定Linux不存在的属性("licenseType":"Windows_Server").该属性的存在将导致部署失败,并显示错误属性"LicenseType"不能与属性"linuxConfiguration"一起使用

I understand there is option to have conditional output for property values, but is it possible to have conditional property itself. For example I have template which creates Microsoft.Compute/VirtualMachine and it's the same template for both Windows and Linux. But for windows I need to specify property which do not exist for Linux ("licenseType": "Windows_Server"). Presense of this property will fail deployment with error The property 'LicenseType' cannot be used together with property 'linuxConfiguration'

我试图弄清楚是否可以仅在Windows映像中包含此属性,同时保持模板相同?

I'm trying to figure out if it's possible to have this property included only for Windows images while keeping template the same?

推荐答案

是可以的,但很hacky.几个选项:

yes it is possible, but hacky. several options:

  1. 创建2个具有不同属性的VM资源,对其进行条件处理,以便仅部署其中一个
  2. 使用联合函数和变量构造结果对象
  3. 将属性附加为单独的部署(可能不适用于所有情况)

让我扩大第二位:

"variables": {
    "baseObject": {
        "propertyOne": "xxx",
        "propertyTwo": "yyy
    }
    "additionalObject: {
        "optionalProperty": "zzz"
    }
}

,然后在您的对象中可以执行以下操作:

and then in your object you can do:

"property": "[if(something, variables('baseObject'), # new line for readability
    union(variables('baseObject'), variables('additionalObject') ))]"

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

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