HowTo: Completely Delete Virtual Machine in Windows Azure

Creating a virtual machine in Windows Azure is quite simple. Open the management console, select the Virtual Machines tab, click New, select the kind of VM, enter some additional data, and wait a while. Then the machine is up and running. Simple!

The deletion seems to be that simple too, but it isn’t. Select the machine to be removed, click the Delete button, confirm, and the machine will be deleted.

As an Azure newbie (as I am at the time of writing), one should read the confirmation question carefully. Besides asking if the VM should be really deleted, it states “The associated disks will not be deleted from your storage account.”

Well, not so bad, one might think, I’ll delete the disk from the storage by myself. Just switch to the Storage tab, select the account, switch to the containers tab, open the vhds, select the VM’s vhd, press the Delete button, confirm … and get stuck. Azure cannot delete the vhd, telling “Blob ‘Vm.vhd’ is in use as virtual machine disk ‘VM’, so the blob cannot be deleted.”

To delete the vhd, one has to go to the Virtual Machines management, select the Disks tab, and delete the disk here. Deleting the disk, one can (and in this case should) delete the associated vhd too, selecting the appropriate option. Only then the vhd is also deleted from the storage. In case you decide to obtain the vhd, you can remove it later from the Storage management tab.

Keeping the disk has one big advantage: it helps you to save money. A VM can be rebuilt from this disk. In case you do not need a VM for a while, delete it, keep the disk, and rebuild the VM when needed.

You should also take a look at the Cloud Services tab of the management console. Azure creates, from what I saw, a cloud service every time a virtual machine is created. The cloud service, of course, is not deleted when the VM is deleted. One has to delete it separately.