一个可以从多个(复制/复制索引)ARM子模板获得输出吗



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

每个子模板在其outputs中返回MSIprincipalIdoutgoingIPAddresses

有没有一种方法可以将返回的单个principalId值组装成一个数组,供父模板调用的后续子模板使用(以便循环遍历principalId的结果数组,并赋予它们对KeyVault的所有相同权限(?

谢谢。

是的,这是可以做到的,尽管没有你希望的那么简单。

要做到这一点,最简单的方法是使用模板的输出组装一个所需的值数组。您需要每个模板获取上一个模板的输出,并将其与自己的输出连接起来,然后将结果作为输出输出输出。示例代码:

{
"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))]"
}

最新更新