动态创建ARM参数名称

问题描述 投票:0回答:2

我有一个场景,我需要动态生成参数名称。像certificate1,certificate2,certificate3 ..等等。目前,所有这些参数都应在主模板中定义。我们可以使用copy来迭代并在Main / Parent模板中动态定义参数Names吗?或者在ARM模板中有哪种方法可以实现这一点?

azure arm-template azure-template
2个回答
0
投票

您可以在变量部分或资源定义\资源属性中使用copy构造。然后你可以使用concat()copyIndex()函数来创建名称。

例:

[concat('something-', copyIndex())]

这会给你一些像-0,something-1,something-2等的名字(copyIndex从0开始)。你也可以通过给它一个偏移数来选择抵消copyIndex

[concat('something-', copyIndex(10))]

这会给你一些名字,比如什么东西-10,东西-11,东西-12等。

复制变量\属性:

"copy": [
    {
        "name": "nameOfThePropertyOrVariableYouWantToIterateOver",
        "count": 3,
        "input": {
            "name": "[concat('something-', copyIndex('nameOfThePropertyOrVariableYouWantToIterateOver', 1))]"    
        }
    }
]

在这里你需要用copyIndex函数指定你指的是哪个循环,你也可以使用偏移量


0
投票

您可以使用Azure模板中的复制功能生成资源的名称,就像certificate1,certificate2,certificate3 ..等等。

示例如下:

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "resources": [
        {
            "apiVersion": "2016-01-01",
            "type": "Microsoft.Storage/storageAccounts",
            "name": "[concat('storage',copyIndex())]",
            "location": "[resourceGroup().location]",
            "sku": {
                "name": "Standard_LRS"
            },
            "kind": "Storage",
            "properties": {},
            "copy": {
                "name": "storagecopy",
                "count": 3
            }
        }
    ],
    "outputs": {}
}

存储名称将是这样的:

存储存储

有关更多详细信息,请参阅Deploy multiple instances of a resource or property in Azure Resource Manager Templates

© www.soinside.com 2019 - 2024. All rights reserved.