手臂模板中的copyindex()错误 [英] copyindex() error in arm template

查看:128
本文介绍了手臂模板中的copyindex()错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的参数文件:

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

Here is my deployment file(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]"
                        }
                    }
                }
            }
        }
    ]
}

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

What the deployment arm template should be doing is launch the subnets with their respective address prefixes (eg: sub1 -> 10.0.1.0/24,sub2 -> 10.0.2.0/24) but when I execute the template from the powershell using the following command:

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

显示以下错误:

在此位置不应使用模板函数"copyIndex". 该功能只能在指定了副本的资源中使用.错误 说copyindex()出了点问题,但我无法 找出问题到底出在哪里.

The template function 'copyIndex' is not expected at this location. The function can only be used in a resource with copy specified. Error says there is something wrong with the copyindex() but I'm unable to find out what exactly is wrong with it.

推荐答案

复制必须看起来像这样:

Copy has to look like this:

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

您丢失了[]

这篇关于手臂模板中的copyindex()错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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