问题
I have a parent template that takes an array (websites
) and invokes a childTemplate (website
) multiple times using the copyIndex()
method to loop through values in the array passed as a parameter.
Each of the child templates returns -- in its output
s -- the MSI principalId
, as well as outgoingIPAddresses
.
Is there a way one can assemble the returned individual principalId
values into an array that can be used by subsequent child template invoked by the parent template (in order to loop through the resulting array of principalId
s and give them all the same rights to a KeyVault
)?
Thank you.
回答1:
Yes, this can be done, although, not as pretty\easy as you would like it to.
easiest way to do this, is assemble an array of values you need using output from the templates. you need each your template to take the output from the previous one and concat it with its own output and spit the result as an output. sample code:
{
"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]"
}
}
}
},
and your state output should just be something like this:
"outputs": {
"state": {
"type": "array",
"value": "[concat(parameters('state'), array(your_actual_output))]"
}
来源:https://stackoverflow.com/questions/53253858/can-one-get-output-from-multiple-copy-copyindex-arm-child-templates