ARM模板中的Concat对象和字符串

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

我有一个parameters.json文件,该文件是一个对象,其中包含针对不同环境的应用程序设置。因此,它看起来像这样:

"parameters": {
    "applicationSettings": {
        "value": {
            "CI": {
                "setting1": "asdf"
            },
            "DEV": {
                "setting1": "1234"
            }
        }
    }
}

在模板文件中,我有一个名为“ applicationSettings”的参数,它是参数文件中的对象。在模板文件中,我还有一个名为“ deploymentEnvironment”的参数,它定义了模板要部署到的环境。因此,当我使用applicationSettings部署功能应用程序时,仅需要获取CI环境的那些设置。

我尝试过:

[concat('parameters(''applicationSettings'').', parameters('deploymentEnvironment'))]

但是发生部署错误:

{
  "ErrorEntity": {
    "ExtendedCode": "51008",
    "MessageTemplate": "The parameter {0} has an invalid value.",
    "Parameters": [
      "properties"
    ],
    "Code": "BadRequest",
    "Message": "The parameter properties has an invalid value."
  }
}

如何在parameters.json文件中引用对象的属性,以便可以根据我的deploymentEnvironment参数提取特定的应用程序设置?

azure azure-resource-manager arm-template
1个回答
2
投票

您需要使用[]表示法:

"[parameters('applicationSettings')[parameters('deploymentEnvironment')]]"

ps。您也可以将它们结合起来:

"[parameters('applicationSettings')[parameters('deploymentEnvironment')].property[xxx]]"
"[parameters('applicationSettings').property[xxx][parameters('deploymentEnvironment')]]"
© www.soinside.com 2019 - 2024. All rights reserved.