The last few days I’ve been testing out many different things with Virtual Networks (especially Site-to-Site VPN). Today I tried cleaning up all the mess I made but I had a few Virtual Networks which I couldn’t delete.
Every time I tried to delete a Virtual Network I got this error message: Virtual network ‘ContosoCloud’ is in use and cannot be deleted. If you recently deleted resources, it might take some time to update the virtual network.
But my Virtual Network wasn’t in use because I made changes to it, it was in use because I didn’t remove the resources linking to this Virtual Network. This is what you’ll need to do to get rid of a Virtual Network and a Local Network (exactly in this order):
- The first step is to delete the gateway in your Virtual Network. This can take a few minutes, so you will need to wait for it to complete before you can continue:
- Once you’ve deleted the Gateway you will need to delete the next link to this Virtual Network. You can find them them under resources in the dashboard of your Virtual Network.
Don’t worry about deleting the Virtual Machine. By deleting them, you’re deleting nothing more than an XML file which describes where to find the data disk, the size of the VM, which ports to open, … So its very easy to re-create the Virtual Machine (with the same data) through the portal or by using PowerShell.
- After removing the gateway and the resources you’ll be able to delete the Virtual Network.
- And the final step, if you linked the Virtual Network to a Local Network you can now also remove the Local Network (which was referenced by the Virtual Network):