代码之家  ›  专栏  ›  技术社区  ›  vishal

arm模板中的copyindex()错误

  •  1
  • vishal  · 技术社区  · 7 年前

    这是我的参数文件:

    "VNetSettings": {
        "value": {
            "name": "VNet1",
            "addressPrefixes": "10.0.0.0/16",
            "subnets": [
                {
                    "name": "sub1",
                    "addressPrefix": "10.0.1.0/24"
                },
                {
                    "name": "sub2",
                    "addressPrefix": "10.0.2.0/24"
                }
            ]
        }
    }
    

    这是我的部署文件(deploy.json)

    {
        "contentversion": "1.0.0.0",
        "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
        "parameters": {
            "VNetSettings": {
                "type": "object"
            },
            "noofsubnets": {
                "type": "int"
            }
        },
        "resources": [
            {
                "apiVersion": "2015-06-15",
                "type": "Microsoft.Network/virtualNetworks",
                "name": "[parameters('VNetSettings').name]",
                "location": "[resourceGroup().location]",
                "properties": {
                    "addressSpace": {
                        "addressPrefixes": [
                            "[parameters('VNetSettings').addressPrefixes]"
                        ]
                    },
                    "copy": {
                        "name": "subnets",
                        "count": "[parameters('noofsubnets')]",
                        "input": {
                            "name": "[parameters('VNetSettings').subnets[copyIndex('subnets',1)].name]",
                            "properties": {
                                "addressPrefix": "[parameters('VNetSettings').subnets[copyIndex('subnets',1)].addressPrefix]"
                            }
                        }
                    }
                }
            }
        ]
    }
    

    部署arm模板应该做的是使用各自的地址前缀启动子网(例如:sub1->10.0.1.0/24,sub2->10.0.2.0/24),但当我使用以下命令从powershell执行模板时:

    New-AzureRmResourceGroupDeployment -Name testing -ResourceGroupName rgname -TemplateFile C:\Test\deploy.json -TemplateParameterFile C:\Test\parameterfile.json 
    

    我显示以下错误:

    此位置不需要模板函数“copyIndex”。 该函数只能在指定了副本的资源中使用。错误 说copyindex()有问题,但我无法 找出它到底出了什么问题。

    2 回复  |  直到 6 年前
        1
  •  6
  •   4c74356b41    7 年前

    副本必须如下所示:

    "copy": [
        {
            "name": "xxx",
            "count": "xxx",
            "input": { ... }
        }
    ]
    

    你失踪了 []

        2
  •  1
  •   Vimalkumar Kalimuthu    4 年前

    copy 不应该在 properties 领域它必须与 属性