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

被刻印的时光 ゝ 提交于 2019-12-20 05:37:09

问题


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 outputs -- 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 principalIds 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!