是否可以从多个 (copy/copyIndex) 个 ARM 子模板获取输出?

Can one get output from multiple (copy/copyIndex) ARM child Templates?

我有一个父模板,它接受一个数组 (websites) 并使用 copyIndex() 方法多次调用子模板 (website) 以循环传递数组中的值作为参数。

每个子模板 returns -- 在其 output 中 -- MSI principalId,以及 outgoingIPAddresses.

有没有一种方法可以 assemble 将返回的单个 principalId 值放入一个数组中,该数组可供父模板调用的后续子模板使用(以便遍历结果数组principalId 人,并赋予他们对 KeyVault)?

的所有相同权利

谢谢。

是的,这是可以做到的,尽管pretty\easy不像您希望的那样。

最简单的方法是 assemble 使用模板输出的一组值。您需要每个模板都从前一个模板中获取输出并将其与自己的输出连接起来,然后将结果作为输出输出。示例代码:

    {
        "name": "reference0", << this one is needed so that the first real one has something to reference, as it cant reference itself
        "type": "Microsoft.Resources/deployments",
        "apiVersion": "2015-01-01",
        "properties": {
            "mode": "Incremental",
            "templateLink": {
                "uri": "yourtemplate",
                "contentVersion": "1.0.0.0"
            }
        },
        "parameters": {
            "state": {
                "value": []
            }
        }
    },
    {
        "name": "[concat('reference', copyIndex(1))]",
        "type": "Microsoft.Resources/deployments",
        "apiVersion": "2015-01-01",
        "copy": {
            "name": "loop",
            "count": "[variables('types')[resourceGroup().name]]"
        },
        "properties": {
            "mode": "Incremental",
            "templateLink": {
                "uri": "yourtemplate",
                "contentVersion": "1.0.0.0"
            },
            "parameters": {
                "state": {
                    "value": "[reference(concat('loop', copyIndex())).outputs.state.value]"
                }
            }
        }
    },

你的状态输出应该是这样的:

"outputs": {
    "state": {
        "type": "array",
        "value": "[concat(parameters('state'), array(your_actual_output))]"
}