Recently I tried deleting a resource group (RG) having Azure Container Instance (ACI) resources which was secured using VNet. I couldn’t get RG deleted completely due to an error related to VNet delete (internally its associated to Network Profile). Then I googled a bit and found this is a common issue where most of the people reported in different forums like GitHub, Stack-overflow etc.
In this blog post I will be covering what is the option to resolve the above issue. Firstly, let me show what is the error you will be seeing in the above scenario.
Subnet raju-subnet-web-dev is in use by
/subscriptions/XXXSubscriptionIdXXX/resourceGroups/raju-rg-dev/providers/Microsoft.Network/
networkProfiles/aci-network-profile-raju-vnet-dev-subnet-web-dev/
containerNetworkInterfaceConfigurations/eth0/ipConfigurations/ipconfigprofile
and cannot be deleted.In order to delete the subnet, delete all the resources within the subnet.
See aka.ms/deletesubnet.
With Error Code: InUseSubnetCannotBeDeleted
Operation name : Delete Virtual Network
At First instance I followed the Microsoft documentation which is mentioned
here but no luck. Script that worked for me is documented below. Root cause for the above error message is after deleting the container group, Network profile is still left over which is associated to VNet. Until Network profile is not deleted it doesn't allow VNet to be removed which in-turns holds your resource group from deleting.
# Replace <your resource group> with the name of your resource group
RES_GROUP=<your resource group>
# Replace <vnet_name> with the name of your VNet name
VNET_NAME=<vnet_name>
# Replace <subnet_name> with the name of your subnet name
SUBNET_NAME=<subnet_name>
# Get network profile ID
NETWORK_PROFILE_ID=$(az network profile list --resource-group $RES_GROUP --query [0].id --output tsv)
Now update the containerNetworkInterfaceConfigurations property in Network profile properties to an empty list (Work around option)
#Update containerNetworkInterfaceConfigurations
az resource update --ids $NETWORK_PROFILE_ID --set properties.containerNetworkInterfaceConfigurations=[]
# Delete the network profile
az network profile delete --id $NETWORK_PROFILE_ID -y
# Delete the subnet
az network vnet subnet delete --resource-group $RES_GROUP --vnet-name $VNET_NAME --name $SUBNET_NAME
# Delete virtual network
az network vnet delete --resource-group $RES_GROUP --name $VNET_NAME
Finally, now you can go ahead and delete your required resource group which was held due to network profile.
References
Comments
Post a Comment