简体   繁体   中英

Azure resource manager template deployments - deletes the existing resources

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 su.net, 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", "Su.net1": "su.net1", "Su.net2": "su.net2", "test.net": ".net1"

},
"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": {}

}

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.

This is covered by thisgithub 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.

You can add/delete a route in an existent route-table without having to reference the other routes. Simply add the route-table name to the route path like in this example:

{ "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "parameters": {}, "variables": {}, "resources": [ { "type": "Microsoft.Network/routeTables/routes", "apiVersion": "2019-06-01", "name": "RouteTableName/RouteName", "properties": { "addressPrefix": "10.0.0.0/8", "nextHopType": ".netLocal" } } ] }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM