I am attempting to delete a virtual network in Azure. When I use the web interface to delete it, it says
Virtual network 'MyVirtualNetwork' is in use and cannot be deleted. If you recently deleted resources, it might take some time to update the virtual network.
Of course, I didn't recently delete resources and there are no VMs using the network. I followed this StackOverflow post here which says that in order to delete a Virtual Network, you must first delete the Virtual Network Gateway.
So, as per the instructions "To delete a virtual network gateway" on MSDN here, I click through the Azure web interface like this:
Virtual Network > *MyVirtualNetwork* > Dashboard > Delete Gateway
And I get this:
Failed to delete the gateway for virtual network 'OneCoreWikiVnet'.
Azure offers no further explanation or other details.
How do I delete this virtual network gateway?
Yes. As you know it correctly that you have to delete all the subnets shown under settings section before you are able to delete the virtual network itself as shown in the snapshot below. As you can see that I've got two subnets namely GatewaySubnet
and Subnet 1
.
You can delete all the subnets except GatewaySubnet
using delete option shown under ...
menu at the end of every row.
If you try deleting the GatewaySubnet
from the same ...
option it gives you an error saying:
The gateway subnet cannot be deleted.
Now the question remains as to how to delete the GatewaySubnet
. Here is the step by step process to accomplish the same:
- Go to
Overview
tab and click on the gateway icon shown with a green check mark in the right pane.
- On the gateway detail screen click the delete button in left pane:
Click Yes
on the warning message which says Are you sure you want to delete this gateway?
This will result in deletion of the GatewaySubnet
. You can observe now on the overview tab that icon of Gateway
has turned grey and its brief description reads Click here to create a gateway
.
- Now just click on the delete button to get rid of the virtual network in entirety.
The azure object hierarchy is as follows.
Virtual Network --> Virtual Network Gateway --> Connections
To delete, you should delete from bottom up (or right to left in this case). Essentially, to delete a VNET gateway you need to ensure that any connection on the gateway is removed first.
Have you tried to use the PowerShell cmdlet to do this?
Remove-AzureVNetGateway -VNetName
You can put -Verbose on there if you're still hitting an error and maybe get a better error response.
-matt