JSON对象作为ARM模板函数参数

时间:2018-11-22 06:11:33

标签: azure templates azure-resource-manager azure-powershell

ARM模板是否提供一种将内联JSON对象定义为模板函数参数的方法?

类似于混合引用,Azure模板函数和JSON对象的东西。

"value": "[concat(reference('ArrayMaker').outputs.fooBarArray.value], 
          [{ "cat": "Tom", "mouse" : "Jerry"}, { "cat":"Garfield", "mouse":"[reference('MouseTrap').outputs.mouseTrap.value]"} ] )]"

使用变量似乎很自然,但是由于该值是通过引用构造的,因此无法使用变量。

1 个答案:

答案 0 :(得分:2)

嗯,不是本地的。您可以使用嵌套部署来解决问题,例如:

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "garfiled": {
            "type": "string"
        },
        "catData": {
            "type": "object",
            "defaultValue": {
                "cat": "Tom"
            }
        }
    },
    "variables": {
        "cat": { <<< if you can\need to construct whole variable in the nested template
            "cat": "Garfield",
            "mouse": "[parameters('garfiled')]"
        },
        "t&j": { <<< if you need to pass in part of the variable to the nested template, you can also create another variable to create an object of a proper structure to union with existing object
            "mouse": "Jerry"
        }
    },
    "resources": [],
    "outputs": {
        "garfiled": {
            "type": "object",
            "value": "[variables('cat')]"
        },
        "t&j": {
            "type": "object",
            "value": "[union(variables('t&j'), parameters('catData'))]"
        }
    }
}

然后,您将使用嵌套模板来传递对该模板的引用并输出结果。