Azure-cli: `az vm delete` does not delete the VM listing under its resource group in the portal

Created on 16 Jan 2019  路  6Comments  路  Source: Azure/azure-cli

When I run az vm delete --resource-group resourceGroup --name vmName, I can see that the VM is removed from when I run az vm lis (it returns an empty list) but the VM resources are not removed from the portal. I saw another issue (#4897) that the disk is not deleted, but I expect everything else to be fully removed from the portal.

To Reproduce
Run az vm create ... and create a VM. Run az vm list to assure yourself that it's there. Then, run az vm delete ... and rerun az vm list again to assure yourself that it's gone. Finally, visit the portal and look at the resource group under which you created the VM. The VM, disk, NSG, PublicIP, VMNic, and VNET are all still listed. You should be able to create a VM with the exact same name (whereas if the VM had not been deleted, you would not be able to do so).

Expected behavior
I expect the VMs to be removed from the portal so it does not, misleadingly, look like there is a VM available. They are considered to be "marked for deletion," but do not get deleted from the portal even if you wait 12 hours.

Compute-cli question

Most helpful comment

@anlatsko if you create the VM in it's own resource group, you can delete the entire resource group when you are done with it, which will delete all the related resources.

All 6 comments

hello @anlatsko , please do you have a screenshot of the vm in portal? (make sure not to capture any sensitive information). And can you show me the command you ran to list the vm and the result.

hi, @adewaleo Thanks for getting back to me.

I was running
az vm list --resource-group anlatsko-rg --subscription 646cce9f-0a1c-4acb-be06-401056b03659. The result is in the last screenshot ([]).

freebsd_in_portal

subscription_confirmed

@anlatsko there are no VMs in the screenshot, just resources previously associated with the VM. There is a virtual network though. But the VM resource itself has been deleted. The VM resource is independent of those other resources.

If you run:

az resource list --resource-group anlatsko -otable

You should see the same resources listed in the CLI.

P.S.

  • We might eventually expose a parameter to delete the VM's disk or other associated resources in az vm delete. However, this can be tricky as some of those resources, such as a virtual network or NSG could be associated with other resources. You can imagine other challenges with exposing such functionality.

  • You don't need to specify the subscription in a command, if it is the default subscription shown after running: az account show

Hi @adewaleo

AH i'm so sorry to have wasted your time. I see that you are correct. I assumed that everything would have been deleted.

Thanks for your help.

@anlatsko if you create the VM in it's own resource group, you can delete the entire resource group when you are done with it, which will delete all the related resources.

Hi @adewaleo Tosin Adewale FTE

AH i'm so sorry to have wasted your time. I see that you are correct. I assumed that everything would have been deleted.

Thanks for your help.

no worries @anlatsko, It's my pleasure to help and clear up any confusion.

Was this page helpful?
0 / 5 - 0 ratings