首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >arm模板中的copyindex()错误

arm模板中的copyindex()错误
EN

Stack Overflow用户
提问于 2018-03-14 14:17:49
回答 2查看 2.8K关注 0票数 0

下面是我的参数文件:

"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‘不应位于此位置。该函数只能在指定了副本的资源中使用。Error说copyindex()有问题,但我无法找出它到底出了什么问题。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-03-14 14:22:51

副本必须看起来像这样:

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

您缺少[]

票数 6
EN

Stack Overflow用户

发布于 2021-04-01 04:52:18

copy不应位于properties字段内。它必须与properties处于同一级别。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49270901

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档