0
votes

When trying to add additional routes to route table in Azure using ARM template, the existing routes are getting removed/deleted. The same behavior is observed when adding new service endpoints for a subnet, post deployment the Route table and NSG are disassociated and the existing serviceend point association is removed. Should all the resources be explicitly reference in ARM template to avoid this behavior. Is there a way this can achieve without listing/referring all the resources associated.

Below template format ----

{ "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "parameters": { }, "functions": [], "variables": { "testroutetable1": "rtable1", "testroutetable2": "rtable2", "Subnet1": "subnet1", "Subnet2": "subnet2", "testvnet": "vnet1"

},
"resources": [
    {
        "name": "[concat(variables('testvnet'),'/',variables('Subnet1'))]",
        "type": "Microsoft.Network/virtualNetworks/subnets",
        "apiVersion": "2018-10-01",
        "location": "East US",
        "properties": {
            "addressPrefix": "10.0.0.0/24",
            "routeTable": {
                "id": "[resourceId('Microsoft.Network/routeTables',variables('testroutetable1'))]"
            }
        }
    },
    {
        "name": "[variables('testroutetable1')]",
        "type": "Microsoft.Network/routeTables",
        "location": "West Europe",
        "apiVersion": "2019-11-01",
        "properties": {
            "routes": [
                {
                    "name": "rtable1-to-xxx01",
                    "properties": {
                        "addressPrefix": "xxxxx",
                        "nextHopType": "VirtualAppliance",
                        "nextHopIpAddress": "xxxxx"
                    }
                },
                {
                    "name": "rtable1-to-xxx02",
                    "properties": {
                        "addressPrefix": "xxxxx",
                        "nextHopType": "VirtualAppliance",
                        "nextHopIpAddress": "xxxx"
                    }
                }

            ]
        }
    },
    {
        "name": "[concat(variables('testvnet'),'/',variables('Subnet2'))]",
        "type": "Microsoft.Network/virtualNetworks/subnets",
        "apiVersion": "2018-10-01",
        "location": "West Europe",
        "properties": {
            "addressPrefix": "10.0.2.0/24",
            "routeTable": {
                "id": "[resourceId('Microsoft.Network/routeTables',variables('testroutetable2'))]"
            }
        }
    },
    {
        "name": "[variables('testroutetable2')]",
        "type": "Microsoft.Network/routeTables",
        "location": "east us",
        "apiVersion": "2019-11-01",
        "properties": {
            "routes": [
                {
                    "name": "rtable2-to-yyy01",
                    "properties": {
                        "addressPrefix": "xxxxxx",
                        "nextHopType": "VirtualAppliance",
                        "nextHopIpAddress": "xxxxx"
                    }
                },
                {
                    "name": "rtable2-to-yyy02",
                    "properties": {
                        "addressPrefix": "xxxxx",
                        "nextHopType": "VirtualAppliance",
                        "nextHopIpAddress": "xxxxxx"
                    }
                }
            ]

        }
    }

],
"outputs": {}

}

2
please paste relevant snippets of your ARM templatesilent

2 Answers

0
votes

If the object's property is of type array then you must provide all of its target value. This applies to security rules on the NSG, routes on the route table, etc.

0
votes

This is covered by this github issue. For certain resources within a virtual network, if you declare them as either child resources of the virtual network, or as independent resources, when the ARM template is deployed, any existing resources are deleted and then the resources are created again.

However, the ARM template for virtual networks also supports deploying these resources as properties. When deploying using this method, any existing resources will not be deleted on each deployment.

Unfortunately this is a long running issue and shows no sign of being resolved in the near future.