1

Here is my parameter file:

"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"
            }
        ]
    }
}

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]"
                        }
                    }
                }
            }
        }
    ]
}

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 

I get displayed with the following error:

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.

4c74356b41
  • 69,186
  • 6
  • 100
  • 141
vishal
  • 1,646
  • 5
  • 28
  • 56
  • whats up with your editing? that was unreadable – 4c74356b41 Mar 14 '18 at 06:23
  • are you asking about the too much spaces between each line? – vishal Mar 14 '18 at 06:26
  • well, if thats the only difference you see between "was" and "is"... I'm only asking this because you clearly put some effort into formatting. but that was completely unreadable. so why did you stop half way through? – 4c74356b41 Mar 14 '18 at 07:00
  • @4c74356b41 Have improved it my next questions. Want to take a look at it? https://stackoverflow.com/questions/49302167/cannot-deserialize-json-array-into-type-microsoft-windowsazure-resourcestack-fr – vishal Mar 16 '18 at 04:17

2 Answers2

6

Copy has to look like this:

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

You are missing []

4c74356b41
  • 69,186
  • 6
  • 100
  • 141
1

copy shouldn't be inside the properties field. It has to be at the same level as properties.