可以从多个(复制/复制索引)ARM 子模板中获得输出吗? [英] Can one get output from multiple (copy/copyIndex) ARM child Templates?

查看:22
本文介绍了可以从多个(复制/复制索引)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.

每个子模板在其 outputs 中返回 MSI principalId 以及 outgoingIPAddresses.

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

有没有一种方法可以将返回的单个 principalId 值组合成一个数组,该数组可由父模板调用的后续子模板使用(以便循环遍历结果数组 principalIds 并赋予他们对 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))]"
}

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

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