0

I'm trying to update the subnet delegations from a parameters file using BICEP but keep getting an error which I can't work out why.

The language expression property 'name' has an invalid array index.

BICEP File:

subnets: [for j in range(0, length(VNetSettings.subnets)): {

          {
            name: VNetSettings.subnets[j].delegations.name
            properties: {
              serviceName: VNetSettings.subnets[j].delegations.properties.serviceName
            }
          }
        ]

Parameters File:

            "value": {
                "Name": "vnet",
                "addressPrefix": "10.230.0.0/23",
                "subnets": [
                    {
                        "name": "data",
                        "addressPrefix": "10.230.1.64/26",
                        "routeTable": "",
                        "unique": false,
                        "nsgRules": [
                            {
                                "name": "DENY-ALL-VNET-INBOUND",
                                "description": "Deny all Virtual Network traffic",
                                "priority": "4000",
                                "direction": "Inbound",
                                "access": "Deny",
                                "protocol": "*",
                                "sourcePortRange": "*",
                                "destinationPortRange": "*",
                                "sourceAddressPrefix": "VirtualNetwork",
                                "destinationAddressPrefix": "VirtualNetwork"
                            }
                        ],
                        "serviceEndpoints":[],
                        "delegations": [
                            {
                                "name": "Microsoft.Web.serverFarms",
                                "properties": {
                                    "serviceName": "Microsoft.Web/serverFarms"
                                }
                            } 
                        ]
                    },

Just can't work out where I'm going wrong.

  • Could you share you bicep file please ? few things tho. You're trying to use `VNetSettings.subnets[j].delegations.properties.serviceName` but the `delegations` is an array in your parameter file. Also, your trying to build a `subnets` property but it doesnt have a service name define. – Thomas Sep 19 '21 at 19:37

1 Answers1

0

Based on the error you've received, I believe the issue has to do with the loop you're constructing. Change your loop to the following:

subnets: [for (subnet, j) in VNetSettings.subnets):

Now, subnet will contain your current subnet object and j will reflect the loop index you're currently on. This corrects the error you see - notably, it's saying you have an invalid array index because you're trying to pass in something that's not actually an index in your original question.

Then just make a few tweaks to the subnet object itself to reflect the use of the reference you're using in the loop (instead of an array index).

{
  name: subnet.delegations.name  
  properties: {
    serviceName: subnet.delegations.properties.serviceName
}
Whit Waldo
  • 4,806
  • 4
  • 48
  • 70