locked
ARM deployment RRS feed

  • Question

  • Hi.

    I thought that it should be possible to deploy the same ARM template multiple times (especially if the template is not changed)?

    I have a simple template with one vnet, one subnet and an ASE. It fails to be deployed multiple times. The first deployment is no problem but the second always fails. I tried with Complete and Incremental deployment mode.

    Do I miss something or is this a bug?

    How to deploy:

    $resourceGroupName = "RTH45"
    $location = "West Europe"
    New-AzResourceGroupDeployment -ResourceGroupName $resourceGroupName -Mode Complete -TemplateFile azuredeploy.json -TemplateParameterFile azuredeploy.parameters.json

    The error is the following:

    New-AzResourceGroupDeployment : 11:03:36 - Resource Microsoft.Network/virtualNetworks 'BackendNet' failed with message
    '{
      "error": {
        "code": "InUseSubnetCannotBeDeleted",
        "message": "Subnet AseSubnet is in use by /subscriptions/**subscription id removed**/resourceGroups/RTH45/
    providers/Microsoft.Web/hostingEnvironments/AppServiceEnvironment and cannot be deleted. In order to delete the subnet,
     delete all the resources within the subnet. See aka.ms/deletesubnet.",
        "details": []
      }
    }'

    It seems that it tries to delete the vnet even though it is not changed.

    The template:

    {
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
    "vnetName": {
    "type": "string",
    "defaultValue": "BackendNet",
    "metadata": {
    "description": "VNet name"
    }
    },
    "aseSubnetName": {
    "type": "string",
    "defaultValue": "AseSubnet",
    "metadata": {
    "description": "Subnet for the ASE"
    }
    },
    "location": {
    "type": "string",
    "defaultValue": "[resourceGroup().location]",
    "metadata": {
    "description": "Location for all resources."
    }
    },
    "aseName": {
    "type": "string",
    "defaultValue": "AppServiceEnvironment",
    "metadata": {
    "description": "Name of the App Service Environment"
    }
    }
    },
    "resources": [
    {
    "type": "Microsoft.Network/virtualNetworks",
    "apiVersion": "2018-10-01",
    "name": "[parameters('vnetName')]",
    "location": "[parameters('location')]",
    "properties": {
    "addressSpace": {
    "addressPrefixes": [
    "10.0.0.0/16"
    ]
    }
    },
    "resources": [
    {
    "apiVersion": "2018-10-01",
    "type": "subnets",
    "name": "[parameters('aseSubnetName')]",
    "location": "[parameters('location')]",
    "properties": {
    "addressPrefix": "10.0.0.0/24"
    },
    "dependsOn": [
    "[resourceId('Microsoft.Network/virtualNetworks', parameters('vnetName'))]"
    ]
    }
    ]
    },
    {
    "apiVersion": "2015-08-01",
    "type": "Microsoft.Web/hostingEnvironments",
    "name": "[parameters('aseName')]",
    "kind": "ASEV2",
    "location": "[parameters('location')]",
    "properties": {
    "name": "[parameters('aseName')]",
    "location": "[parameters('location')]",
    "ipSslAddressCount": 0,
    "internalLoadBalancingMode": 1,
    "dnsSuffix": "energinettest.dk",
    "virtualNetwork": {
    "Id": "[resourceId('Microsoft.Network/virtualNetworks', parameters('vnetName'))]",
    "Subnet": "[parameters('aseSubnetName')]"
    }
    },
    "dependsOn": [
    "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('vnetName'), parameters('aseSubnetName'))]"
    ]
    }
    ]
    }


    Friday, June 14, 2019 9:29 AM

Answers

  • Hi R. Therkildsen,

    This is because the subnet properties is missing from the vnet properties in the template. Specify all properties for the resource, not just the ones you're updating. A common misunderstanding is to think properties that are not specified are left unchanged.

    https://docs.microsoft.com/bs-cyrl-ba/azure/azure-resource-manager/deployment-modes

    You can use the below template:

    {
    
      "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    
      "contentVersion": "1.0.0.0",
    
      "parameters": {
    
        "vnetName": {
    
          "type": "string",
    
          "defaultValue": "BackendNet",
    
          "metadata": {
    
            "description": "VNet name"
    
          }
    
        },
    
        "aseSubnetName": {
    
          "type": "string",
    
          "defaultValue": "AseSubnet",
    
          "metadata": {
    
            "description": "Subnet for the ASE"
    
          }
    
        },
    
        "location": {
    
          "type": "string",
    
          "defaultValue": "[resourceGroup().location]",
    
          "metadata": {
    
            "description": "Location for all resources."
    
          }
    
        },
    
        "aseName": {
    
          "type": "string",
    
          "defaultValue": "AppServiceEnvironment",
    
          "metadata": {
    
            "description": "Name of the App Service Environment"
    
          }
    
        }
    
      },
    
      "resources": [
    
        {
    
          "type": "Microsoft.Network/virtualNetworks",
    
          "apiVersion": "2018-10-01",
    
          "name": "[parameters('vnetName')]",
    
          "location": "[parameters('location')]",
    
          "properties": {
    
            "addressSpace": {
    
              "addressPrefixes": [
    
                "10.0.0.0/16"
    
              ]
    
            },
    
            "subnets": [
              {
                "name": "[parameters('aseSubnetName')]",
                "properties": {
                  "addressPrefix": "10.0.0.0/24"
                }
              }
            ]
    
          },
    
          "resources": [
    
            {
    
              "apiVersion": "2018-10-01",
    
              "type": "subnets",
    
              "name": "[parameters('aseSubnetName')]",
    
              "location": "[parameters('location')]",
    
              "properties": {
    
                "addressPrefix": "10.0.0.0/24"
    
              },
    
              "dependsOn": [
    
                "[resourceId('Microsoft.Network/virtualNetworks', parameters('vnetName'))]"
    
              ]
    
            }
    
          ]
    
        },
    
        {
    
          "apiVersion": "2015-08-01",
    
          "type": "Microsoft.Web/hostingEnvironments",
    
          "name": "[parameters('aseName')]",
    
          "kind": "ASEV2",
    
          "location": "[parameters('location')]",
    
          "properties": {
    
            "name": "[parameters('aseName')]",
    
            "location": "[parameters('location')]",
    
            "ipSslAddressCount": 0,
    
            "internalLoadBalancingMode": 1,
    
            "dnsSuffix": "energinettest.dk",
    
            "virtualNetwork": {
    
              "Id": "[resourceId('Microsoft.Network/virtualNetworks', parameters('vnetName'))]",
    
              "Subnet": "[parameters('aseSubnetName')]"
    
            }
    
          },
    
          "dependsOn": [
    
            "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('vnetName'), parameters('aseSubnetName'))]"
    
          ]
    
        }
    
      ]
    
    }

    Here is another stackoverflow thread on the same:

    https://stackoverflow.com/questions/55901747/azure-arm-code-inusesubnetcannotbedeleted-when-trying-to-update-vnet

    Hope this helps!

    Monday, June 17, 2019 1:34 AM

All replies

  • Hi R. Therkildsen,

    This is because the subnet properties is missing from the vnet properties in the template. Specify all properties for the resource, not just the ones you're updating. A common misunderstanding is to think properties that are not specified are left unchanged.

    https://docs.microsoft.com/bs-cyrl-ba/azure/azure-resource-manager/deployment-modes

    You can use the below template:

    {
    
      "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    
      "contentVersion": "1.0.0.0",
    
      "parameters": {
    
        "vnetName": {
    
          "type": "string",
    
          "defaultValue": "BackendNet",
    
          "metadata": {
    
            "description": "VNet name"
    
          }
    
        },
    
        "aseSubnetName": {
    
          "type": "string",
    
          "defaultValue": "AseSubnet",
    
          "metadata": {
    
            "description": "Subnet for the ASE"
    
          }
    
        },
    
        "location": {
    
          "type": "string",
    
          "defaultValue": "[resourceGroup().location]",
    
          "metadata": {
    
            "description": "Location for all resources."
    
          }
    
        },
    
        "aseName": {
    
          "type": "string",
    
          "defaultValue": "AppServiceEnvironment",
    
          "metadata": {
    
            "description": "Name of the App Service Environment"
    
          }
    
        }
    
      },
    
      "resources": [
    
        {
    
          "type": "Microsoft.Network/virtualNetworks",
    
          "apiVersion": "2018-10-01",
    
          "name": "[parameters('vnetName')]",
    
          "location": "[parameters('location')]",
    
          "properties": {
    
            "addressSpace": {
    
              "addressPrefixes": [
    
                "10.0.0.0/16"
    
              ]
    
            },
    
            "subnets": [
              {
                "name": "[parameters('aseSubnetName')]",
                "properties": {
                  "addressPrefix": "10.0.0.0/24"
                }
              }
            ]
    
          },
    
          "resources": [
    
            {
    
              "apiVersion": "2018-10-01",
    
              "type": "subnets",
    
              "name": "[parameters('aseSubnetName')]",
    
              "location": "[parameters('location')]",
    
              "properties": {
    
                "addressPrefix": "10.0.0.0/24"
    
              },
    
              "dependsOn": [
    
                "[resourceId('Microsoft.Network/virtualNetworks', parameters('vnetName'))]"
    
              ]
    
            }
    
          ]
    
        },
    
        {
    
          "apiVersion": "2015-08-01",
    
          "type": "Microsoft.Web/hostingEnvironments",
    
          "name": "[parameters('aseName')]",
    
          "kind": "ASEV2",
    
          "location": "[parameters('location')]",
    
          "properties": {
    
            "name": "[parameters('aseName')]",
    
            "location": "[parameters('location')]",
    
            "ipSslAddressCount": 0,
    
            "internalLoadBalancingMode": 1,
    
            "dnsSuffix": "energinettest.dk",
    
            "virtualNetwork": {
    
              "Id": "[resourceId('Microsoft.Network/virtualNetworks', parameters('vnetName'))]",
    
              "Subnet": "[parameters('aseSubnetName')]"
    
            }
    
          },
    
          "dependsOn": [
    
            "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('vnetName'), parameters('aseSubnetName'))]"
    
          ]
    
        }
    
      ]
    
    }

    Here is another stackoverflow thread on the same:

    https://stackoverflow.com/questions/55901747/azure-arm-code-inusesubnetcannotbedeleted-when-trying-to-update-vnet

    Hope this helps!

    Monday, June 17, 2019 1:34 AM
  • Hi R. Therkildsen,

    Let us know if there is anything else related to this thread that we can assist you with, else please feel free to mark and close this out if the above response has been of help! Thanks again for reaching out!

    Saturday, June 22, 2019 8:58 AM
  • That was it. Thanks a lot.
    Wednesday, June 26, 2019 7:21 AM