Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Azure ARM模板动态变量绑定_Azure_Templates_Variables_Dynamic_Azure Resource Manager - Fatal编程技术网

Azure ARM模板动态变量绑定

Azure ARM模板动态变量绑定,azure,templates,variables,dynamic,azure-resource-manager,Azure,Templates,Variables,Dynamic,Azure Resource Manager,如何通过传递动态变量从列表中获取键的值 我的代码 "variables": { "locationCodeList": [ { "southcentralus": "ussc", "northcentralus": "usnc&quo

如何通过传递动态变量从列表中获取键的值

我的代码

    "variables": {
                "locationCodeList": [
                  {
                    "southcentralus": "ussc",
                    "northcentralus": "usnc",
                    "westcentralus": "uswc",
                    "centralus": "usce",
                    "westus": "uswe",
                    "westus2": "usw2"
                  }
                ],
                "locCode": "[variables('locationCodeList')[0].(resourceGroup().location)]"
}

我想在resourceGroup()时获取值ussc。位置为southcentralus。有没有更好的方法来实现这一点?

它的json,这样您就可以使用[]

我使用这个命令来测试下面的模板。 az部署组创建--资源组rg测试--模板文件。\blank.template

更新以使locationCodeList成为对象而不是数组

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
  },
  "variables": {
                "locationCodeList": {
                    "southcentralus": "ussc",
                    "northcentralus": "usnc",
                    "westcentralus": "uswc",
                    "centralus": "usce",
                    "westus": "uswe",
                    "westus2": "usw2"
                  },
                "locCode": "[variables('locationCodeList')[resourceGroup().location]]"
},
  "resources": [
  ],
  "outputs": {
    "locCodeOutput": {
      "type": "string",
      "value": "[variables('locCode')]"
    }
  }
}
如果有必要,我想离开它

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
  },
  "variables": {
                "locationCodeList": [
                  {
                    "southcentralus": "ussc",
                    "northcentralus": "usnc",
                    "westcentralus": "uswc",
                    "centralus": "usce",
                    "westus": "uswe",
                    "westus2": "usw2"
                  }
                ],
                "locCode": "[variables('locationCodeList')[0][resourceGroup().location]]"
},
  "resources": [
  ],
  "outputs": {
    "locCodeOutput": {
      "type": "string",
      "value": "[variables('locCode')]"
    }
  }
}

请注意,对于简单的对象属性引用,您不需要[0]——您可以在var定义中删除它和[]——这里有一个类似的示例:True可以更新变量,因此它不是数组,而是一个JSON对象。谢谢你的点名,我已经更新了我的答案,以反映这一点,我应该这样做。