How to delete a VNET from the Azure portal

After writing this article here “Create a VNET and access an Azure VM hosted within it from an App Services Web App” I wanted to then remove the resources because I was using them for testing and not for a real production, money generating project.  I also wrote this article here “Create and deploy an ASP.NET Core Web API to Azure Windows” that discusses more VNET integration with an Azure App Service and an Azure VM.  #VNET #Azure #AzureAppService #AzureVM

This is also a helpful article.

Because in those examples, I created everything I needed for that project in a specific Resource Group, I knew that to remove the features used while testing that scenario, I simply needed to remove all the resources within it.  As seen in Figure 1, the features I created were:

  • Azure VM, a Public IP address, an NSG, a Network Interface and an associated storage account
  • Azure App Service Plan (S1) and an associated Web App
  • Virtual Network, a Public IP address and a Virtual Network Gateway

image

Figure 1, how to delete a VNET from Azure

I clicked on the VNET and as there was a delete button I decided to click on it.  However, I received this error:

Failed to delete virtual network
Failed to delete virtual network ‘VPN-AM2-VNET’. Error: Subnet default is in use by /subscriptions/###############/resourceGroups/VPN-AM2-RG/providers/Microsoft.Network/networkInterfaces/vpn-am2-vm1871/ipConfigurations/ipconfig1 and cannot be deleted.

Failed to delete virtual network
Failed to delete virtual network ‘VNET-LG1-001’. Error: Virtual Network /subscriptions/##########resourceGroups/VNET-LG1-001-RG/providers/Microsoft.Network/virtualNetworks/VNET-LG1-001 is in use.

Delete virtual network
This virtual network is in use and cannot be deleted.  If you recently deleted resources, it might take some time to update the virtual network.

Which made sense to me.  Also, the error message identified the dependency which caused the deleted to fail, so I attempted to delete the Network Interface.  I received this error:

Failed to delete network interface
Failed to delete network interface ‘vpn-am2-vm1871’. Error: Network Interface /subscriptions/##############/resourceGroups/VPN-AM2-RG/providers/Microsoft.Network/networkInterfaces/vpn-am2-vm1871 is used by existing VM /subscriptions/####################/resourceGroups/VPN-AM2-RG/providers/Microsoft.Compute/virtualMachines/VPN-AM2-VM1.

Again, it did not work, but the error identified the dependency and therefore, I opened the Azure VM I created to host my ASP.NET Core API and attempted to deleted that.  And the result was successful.  Therefore, the order in which I was able to remove all my Azure features I used to test a Point-to-Site #PointToSite connection between my Azure App Service Web App and an Azure VM hosted in a VNET follows:

  • Azure VM (not classic)
  • Network Interface
  • Azure VM Public IP address
  • Azure VM Network Security Group (NSG)
  • Virtual Network Gateway
  • Virtual Network Public IP address
  • Azure App Service Web App (if there is only 1, the App Service Plan will be deleted automatically)
  • Storage Account
  • Virtual Network
  • Resource Group

I was doing the above deletions in that order in numerous subscriptions and in one of the I got this error when I tried to delete the storage.

Failed to delete storage account
Failed to delete storage account ‘function12e3d4bcb4ce’. Error: The scope ‘/subscriptions/############/resourceGroups/vpn-am2-rg/providers/Microsoft.Storage/storageAccounts/function12e3d4bcb4ce’ cannot perform delete operation because following scope(s) are locked: ‘/subscriptions/###########/resourcegroups/VPN-AM2-RG/providers/Microsoft.Storage/storageAccounts/function12e3d4bcb4ce’. Please remove the lock and try again.

I tried to remove the Resource Group and got this error:

Delete resource group ######### failed
The resource group ########## is locked and can’t be deleted.  Click here to manage lock for this resource group.

On the navigation pane on the left side of the resource group page, you will see an item called Locks.  Click on that to view the locks and click each to remove the lock on the resource.  Similar to that shown in Figure 2.  Right click on the lock and select Delete.

image

Figure 2, cannot delete Azure feature because it is locked

Then, you can delete the storage account and finally the Resource Group.

NOTE: when the VNET was classic, I had to remove the Subnet configurations in order to remove the VNET, just click on Subnet, right-click the entry, then Delete.