一个人可以从多个(copy/copyIndex)ARM子模板中获取输出吗? [英] Can one get output from multiple (copy/copyIndex) ARM child Templates?

查看:71
本文介绍了一个人可以从多个(copy/copyIndex)ARM子模板中获取输出吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个父模板,该模板带有一个数组(websites)并使用copyIndex()方法多次调用childTemplate(website),以遍历作为参数传递的数组中的值.

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.

每个子模板都会在其output中返回MSI principalIdoutgoingIPAddresses.

Each of the child templates returns -- in its outputs -- the MSI principalId, as well as outgoingIPAddresses.

有没有一种方法可以将返回的各个principalId值组合成一个数组,该数组可以由父模板调用的后续子模板使用(以便循环遍历principalId s的结果数组并提供它们对KeyVault拥有相同的权利?

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)?

谢谢.

推荐答案

是的,虽然不是您想要的那样漂亮/容易,但是可以做到这一点.

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

这篇关于一个人可以从多个(copy/copyIndex)ARM子模板中获取输出吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆