内联对象作为链接模板部署的参数值

时间:2018-10-09 17:13:38

标签: azure azure-resource-manager arm-template azure-template

我希望能够将内联对象作为参数值传递给链接模板。用例是我有一个部署服务总线(或其他资源)的模板和一个部署Web应用程序的模板。我想构建一个将两个组件结合在一起的模板。我希望Web应用程序模板具有一个名为userProvidedAppSettings的对象参数,我可以将其与某些默认值合并,然后将该结果对象分配为Microsoft.Web / site / config / appsettings资源的属性值。 / p>

看来您当前无法在参数的嵌入式对象值中使用引用或列表键功能,请参见以下示例中的userProvidedAppSettings

这是否可能,并且我没有使用适当的约定?我没有在文档中看到任何有关此的内容。

{
    "apiVersion": "[parameters('apiVersion')]",
    "name": "[variables('serviceBusDeploymentName')]",
    "type": "Microsoft.Resources/deployments",
    "properties": {
        "mode": "Incremental",
        "templateLink": {
            "uri": "[parameters('templateOneUri')]",
            "contentVersion": "1.0.0.0"
         },
         "parameters": {
             "environment": { "value": "[parameters('environment')]" },
             "appName": { "value": "[parameters('appName')]" }
          }
     }
},
{
        "apiVersion": "[parameters('apiVersion')]",
        "name": "[variables('applicationDeploymentName')]",
        "type": "Microsoft.Resources/deployments",
        "properties": {
            "mode": "Incremental",
            "templateLink": {
                "uri": "[parameters('templateTwoUri')]",
                "contentVersion": "1.0.0.0"
             },
             "parameters": {
                 "environment": { "value": "[parameters('environment')]" },
                 "appName": { "value": "[parameters('appName')]" },
                 "userProvidedAppSettings" : { "value": { "serviceBusConnectionString": "[reference(variables('serviceBusDeploymentName')).outputs.connectionString.value]" } }
              }
         }
    }

编辑:

为澄清起见,这是关于链接的模板参数值的行为。我专门问这个问题:

"parameters": {
    // Allowed:
    "param1": { "value": "[parameters('environment')]" },
    "param2": { "value": "[reference('otherDeployment').outputs.something.value]" },
    "param3": { "value": { "this": "is allowed",
                           "inline": "is allowed" } },
    // NOT Allowed
    "param4": { "value": { "this": "is NOT allowed".
                           "foo": "[reference('otherDeployment').outputs.something.value]" } }
}
允许将

reference输出作为值,允许将内联对象作为值,但是不允许使用其值包括reference(或来自list函数的隐式引用)的内联对象。我想知道这是否可以通过其他约定实现,还是应该将其添加到所需功能列表中。

2 个答案:

答案 0 :(得分:0)

对于您的问题,不确定,但是您可以尝试使用links and nested templates。您可以在主模板中获取链接模板的值。

您可以在链接模板输出中定义变量,并在主模板中使用它。有一个简单的示例here。希望这会对您有所帮助!

答案 1 :(得分:0)

您可以使用union()函数来构建所需的对象,并将其作为值传递给参数。

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "firstObject": {
            "type": "object",
            "defaultValue": {"one": "a", "two": "b", "three": "c1"}
        },
        "secondObject": {
            "type": "object",
            "defaultValue": {"three": "c2", "four": "d", "five": "e"}
        }
    },
    "resources": [],
    "outputs": {
        "objectOutput": {
            "type": "object",
            "value": "[union(parameters('firstObject'), parameters('secondObject'))]"
        }
    }
}