Azure-quickstart-templates: 201-site-to-site-vpn: How to use multiple subnets in localAddressPrefix parameter?

Created on 6 Apr 2016  路  10Comments  路  Source: Azure/azure-quickstart-templates

Template

201-site-to-site-vpn
https://github.com/Azure/azure-quickstart-templates/tree/master/101-site-to-site-vpn-create

Issue Details

I'm trying to add multiple subnets to the localAddressPrefix parameter in the 201-site-to-site-vpn template. The template currently has a string value which appears to support a single subnet.
I'd like to modify the template in order to support multiple subnets for the local gateway side of the connection.

I tried modifying the parameter to be an array as follows:

        "localAddressPrefix": {
            "type": "array",
            "defaultValue": [
                "192.168.1.0/24",
                "192.168.2.0/24",
                "192.168.3.0/24",
                "192.168.4.0/24",
                "192.168.5.0/24"
            ],
            "metadata": {
                "description": "Array of CIDR blocks representing the address space of the OnPremise VPN network's Subnet"
            }
        },

I did not modify the resources for the template.

I did modify the azuredeploy.parameters.json to support the multiple subnets with the array as follows:

        "localAddressPrefix": {
            "value": ["192.168.1.0/24",
                "192.168.2.0/24",
                "192.168.3.0/24",
                "192.168.4.0/24",
                "192.168.5.0/24"
                     ]
        },

Reproduce/Question

When I execute the template using azure-cli on OSX (v. 0.9.15) I get an error for the deployment indicating inability to iterate over the array, but with a more generic error message.

How should I modify the template to be able to add multiple subnets in the localAddressPrefix parameter?

Here is the command I use to execute the deployment:

azure group deployment create -g MyWestusRG1 -n MyWestusS2SVPNdeployment -vv -f \
azuredeploy.json -e \
azuredeploy.parameters.json

Errors

Here are some relevant errors I get from the console:

statusCode":"BadRequest","statusMessage":{"error":{"code":"InvalidRequestFormat","message":"Cannot parse the request.","details":[{"code":"InvalidJson","message":"Error reading string. Unexpected token: StartArray. Path 'properties.localNetworkAddressSpace.addressPrefixes[0]', line 1, position 84."}
error:   Deployment provisioning state was not successful
2016-04-05T22:34:25.866Z - error:   Cannot parse the request.
2016-04-05T22:34:25.867Z - error:   Cannot read property 'forEach' of undefined

I think I may need to modify the resource potentially to solve this, but I also wanted to make sure the modifications to the parameters were correct.

Many thanks

question

Most helpful comment

This happens because you are passing an array inside another array.

You have to remove the [] from the resource because you are already passing an array.

"resources": [
    {
        "apiVersion": "[variables('api-version')]",
        "type": "Microsoft.Network/localNetworkGateways",
        "name": "[parameters('localGatewayName')]",
        "location": "[parameters('location')]",
        "properties": {
            "localNetworkAddressSpace": {
                "addressPrefixes": "[parameters('localAddressPrefixArray')]",
            },
            "gatewayIpAddress": "[parameters('localGatewayIpAddress')]"
        }
    },

All 10 comments

Adding @TheAndrewCook who wrote the template. Also look at the Network Gateway REST API https://msdn.microsoft.com/en-us/library/mt163859.aspx

Try substituting that array directly into the resource to see if you get the same error.

@singhkay
@TheAndrewCook
Thanks for response.
I did try modifying the resource to add the array values directly, but also get an error there as well.

    "resources": [
        {
            "apiVersion": "[variables('api-version')]",
            "type": "Microsoft.Network/localNetworkGateways",
            "name": "[parameters('localGatewayName')]",
            "location": "[parameters('location')]",
            "properties": {
                "localNetworkAddressSpace": {
                    "addressPrefixes": [
                        "192.168.0.0/24",
                        "192.168.1.0/24",
                        "192.168.2.0/24",
                        "192.168.3.0/24",
                        "192.168.4.0/24",
                        "192.168.5.0/24"
                    ]
                },
                "gatewayIpAddress": "[parameters('localGatewayIpAddress')]"
             }
        },
...

And here is the error that I get from the azure-cli console:

error:   Deployment provisioning state was not successful
error:   AddressSpace of the virtual network /subscriptions/<snipped>/resourceGroups/MY-WESTUS-VNET-RG1/providers/Microsoft.Network/virtualNetworks/MY-WESTUS-VNET does not have any address prefixes in addressPrefixes array. AddressSpace and prefixes must be specified within properties object.

data:    DeploymentName     : MY-WESTUS-S2S-VPN-DEPLOYMENT
data:    ResourceGroupName  : MY-WESTUS-VNET-RG1
data:    ProvisioningState  : Failed
data:    Timestamp          : 2016-04-07T23:20:03.6169613Z
data:    Mode               : Incremental
data:    Name                    Type          Value
data:    ----------------------  ------------  --------------------------------------------------------------------------------------------------------------------------------------------------------------------
data:    location                String        West US
data:    vpnType                 String        RouteBased
data:    localGatewayName        String        MY-WESTUS-LOCAL-GATEWAY1
data:    localGatewayIpAddress   String        159.203.244.225
data:    localAddressPrefix      Array         192.168.0.0/24,192.168.1.0/24,192.168.2.0/24,192.168.3.0/24,192.168.4.0/24,192.168.5.0/24
data:    virtualNetworkName      String        MY-WESTUS-VNET
data:    azureVNetAddressPrefix  String        10.115.0.0/18
data:    subnetName              String        AZURE-WESTUS-VPN-GATEWAY1-SUBNET
data:    gatewaySubnetPrefix     String        10.115.63.0/25
data:    gatewayPublicIPName     String        AZURE-WESTUS-VPN-GATEWAY1-IP
data:    gatewayName             String        AZURE-WESTUS-VPN-GATEWAY1
data:    gatewaySku              String        Standard
data:    connectionName          String        AZURE-WESTUS-VPN2MY-PHX
data:    sharedKey               SecureString  undefined
info:    group deployment create command OK

And here is the error as displayed in the Azure Deployments Console:

At least one resource deployment operation failed. Please list deployment operations for details. Please see http://aka.ms/arm-debug for usage details. (Code: DeploymentFailed)  

AddressSpace of the virtual network /subscriptions/<snipped>/resourceGroups/MY-WESTUS-VNET-RG1/providers/Microsoft.Network/virtualNetworks/GAP-WESTUS-VNET does not have any address prefixes in addressPrefixes array. AddressSpace and prefixes must be specified within properties object. (Code: VnetAddressPrefixesIsNullOrEmpty)  

I can create a workaround by making multiple localAddressPrefix parameters and corresponding usage as properties in the Resource. I was actually hoping to have the resource treat the parameter array as an iterator loop. This would in essence have created multiple instances of the property objects.
I tried multiple attempts to use the copy object feature and index in the template, but had trouble making this work since I needed to iterate on properties and not the actual resource itself. There may be a workaround, but I could not figure it out.

My approach looks like this in the azuredeploy.json parameters:

        "localAddressPrefix1": {
            "type": "string",
            "defaultValue": 
                "192.168.1.0/24",
            "metadata": {
                "description": "Array of CIDR blocks representing the address space of the OnPremise VPN network's Subnet"
            }
        },

        "localAddressPrefix2": {
            "type": "string",
            "defaultValue": 
                "192.168.2.0/24",
            "metadata": {
                "description": "Array of CIDR blocks representing the address space of the OnPremise VPN network's Subnet"
            }
        },

        "localAddressPrefix3": {
            "type": "string",
            "defaultValue": 
                "192.168.3.0/24",
            "metadata": {
                "description": "Array of CIDR blocks representing the address space of the OnPremise VPN network's Subnet"
            }
        },

        "localAddressPrefix4": {
            "type": "string",
            "defaultValue": 
                "192.168.4.0/24",
            "metadata": {
                "description": "Array of CIDR blocks representing the address space of the OnPremise VPN network's Subnet"
            }
        },

        "localAddressPrefix5": {
            "type": "string",
            "defaultValue": 
                "192.168.5.0/24",
            "metadata": {
                "description": "Array of CIDR blocks representing the address space of the OnPremise VPN network's Subnet"
            }
        },

And then this change in the azuredeploy.json resources block:

    "resources": [
        {
            "apiVersion": "[variables('api-version')]",
            "type": "Microsoft.Network/localNetworkGateways",
            "name": "[parameters('localGatewayName')]",
            "location": "[parameters('location')]",
            "properties": {
                "localNetworkAddressSpace": {
                    "addressPrefixes": [
                        "[parameters('localAddressPrefix1')]",
                        "[parameters('localAddressPrefix2')]",
                        "[parameters('localAddressPrefix3')]",
                        "[parameters('localAddressPrefix4')]",
                        "[parameters('localAddressPrefix5')]"

                    ]
                },
                "gatewayIpAddress": "[parameters('localGatewayIpAddress')]"
            }
        },

Hi,

I have also been looking to use an array, like the example from with the application gateway (backendAddresses). https://github.com/Azure/azure-quickstart-templates/tree/master/101-application-gateway-create. Apart from using multiple parameters is there not another option ?

In case you haven't resolved this, I managed to pass an array of address prefixes successfully using the take() function. I'm passing the array as a template parameter, then as an input variable for a resource deployment (child template) from PowerShell.

{
"name": "[parameters('vNetSettings').vNetName]",
"type": "Microsoft.Network/virtualNetworks",
"apiVersion": "2015-06-15",
"location": "[resourceGroup().location]",
"properties": {
"addressSpace": {
"addressPrefixes": "[take(parameters('vNetSettings').vNetAddressPrefix, length(parameters('vNetSettings').vNetAddressPrefix))]"
},
"subnets": "[take(parameters('vNetSettings').subnetSettings, length(parameters('vNetSettings').subnetSettings))]"
}
}

could you post the full script? what is in the template and what is in the parameters file?
this does not look like the

"localNetworkAddressSpace": {
"addressPrefixes": [
"[parameters('localAddressPrefix')]"
]

Hello,

Below is attached the localNetworkGateways which are part of the route base VPN configuration.

Parameters

"CustomerlocalSubnets": {
  "defaultValue": null,
  "type": "string"
  }

Local networks
{
"apiVersion": "2015-06-15",
"type": "Microsoft.Network/localNetworkGateways",
"name": "[variables('localGatewayName')]",
"location": "[variables(parameters('AzureRegion')).Location]",
"properties": {
"localNetworkAddressSpace": {
"addressPrefixes": [
"[parameters('CustomerlocalSubnets')]"
]
},
"gatewayIpAddress": "[parameters('CustomerVPNEndpointExternalIP')]"
}
},

This happens because you are passing an array inside another array.

You have to remove the [] from the resource because you are already passing an array.

"resources": [
    {
        "apiVersion": "[variables('api-version')]",
        "type": "Microsoft.Network/localNetworkGateways",
        "name": "[parameters('localGatewayName')]",
        "location": "[parameters('location')]",
        "properties": {
            "localNetworkAddressSpace": {
                "addressPrefixes": "[parameters('localAddressPrefixArray')]",
            },
            "gatewayIpAddress": "[parameters('localGatewayIpAddress')]"
        }
    },

Was there ever a fix for this as I am getting the same issue?

@fbinotto wrote the right answer and solved the issue!

Was this page helpful?
0 / 5 - 0 ratings