Azure ARM模板变量条件

问题描述 投票:0回答:1

我有一个手臂模板,我正在尝试将区域条件应用到其中。就像Region变量等于EUW一样,则使用变量westeurope。可以将其作为参数中的数组来完成,还是应该将其作为带有if语句的变量数组?

我在其他线程上看到,ARM模板实际上更多地是一个if / else语句,而不是if / ifelse / else。

经典示例:

"availabilitySet": "[if(equals(parameters('production'), 'Yes'), variables('availabilitySetId'), json('null'))]",

我正在寻找这样的东西:

"parameters": {
    "Region": {
        "type": "string",
        "defaultValue": "USSC",
        "allowedValues": [
            "AIE",
            "BRS",
            "EUW",
            "USSC"
        ],
        "metadata": {
            "description": "Select Region"
        }
    }
},

"variables": {
    "regionReference": {
        "eastasia": "[if(equals(parameters('Region'), 'AIE')],
        "brazilsouth": "[if(equals(parameters('Region'), 'BRS')],
        "westeurope": "[if(equals(parameters('Region'), 'EUW')],
        "southcentral": "[if(equals(parameters('Region'), 'USSC')],
    }
}

请您原谅我。我也考虑过条件语句,但也没有使它起作用。

json azure
1个回答
0
投票

您可以执行此操作:

"regionReference": {
    "AIE": "eastasia",
    "BRS": "brazilsouth",
    "EUW": "westeurope",
    "USSC": "southcentral"
}

然后您可以参考您选择的区域:

"location": "[variables('regionReference').[parameters('Region')])]"

尽管,我不明白你为什么在没有任何真正原因的情况下使这里的生活更加艰难

© www.soinside.com 2019 - 2024. All rights reserved.