Unable to delete a virtual network’s subnet due to serviceAssociationLinks and delegation
Error details
Failed to delete subnet 'subnet name'. Error: Subnet <subnet name> is in use by /subscriptions/<id>/resourceGroups/<rgname>/providers/Microsoft.Network/virtualNetworks/<vnetname>/subnets/<subnetname>/serviceAssociationLinks/AppServiceLink and cannot be deleted. In order to delete the subnet, delete all the resources within the subnet.
The above error is due to a non-recommended steps/way of deletion of webapp. Following are the steps to be followed, to resolve such issues and to be able to delete the azure network components
- List the subnet list with the cli
az network vnet subnet list --resource-group <rg name> --vnet-name <vnet name>
- Find the SAL from the result from the tag “serviceAssociationLinks/link”
- Example:
"/subscriptions/<sub name>/resourceGroups/<rg name>/providers/Microsoft.Web/serverfarms/<SALNAME>
- Example:
- Create a new Web App under the same Subscription and Resource Group with same Web App name, type etc. which was deleted before
- Make sure that under “Networking” tab, “Enable virtual network integration” is selected
- Select the Virtual Network “Backends”
- Under “Outbound access”, select “Enable Vnet integration”.
- Selected the same subnet as used before
- After the deployment found successful, visit app service plan section
- Go to Settings>Networking>VNet Integration and select “Click here to manage”.
- Make sure that, “Regional VNet integrations” is 1/2, with VNet selected in previous attempt
- Under Settings>Networking>Outbound traffic configuration, disconnect the Virtual network integration
Above steps will help to delete the “serviceAssociationLinks”. Further, we can be able to remove the delegation from the subnet and delete it