Does Deleting an Azure Managed Disk Also Delete Snapshots?

TL;DR: No.

I’ve been working with numerous customers on Windows Virtual Desktop (WVD) deployments since I started my position at Microsoft. During the process of manually* creating an image, it’s common to take snapshots. I especially recommend taking snapshots before sysprepping the image.

Once you sysprep an Azure VM, the VM itself is unusable; it won’t successfully boot anymore. So keeping the VM around is useless once you have the generalized image you need to set up WVD session hosts. However, you want to keep the pre-sysprep snapshot around. So the question arises, in order to keep the snapshot, do you need to keep the disk? Keep in mind that both the disk and snapshot are Azure resources and incur a charge.

Here’s an Azure CLI test script that will help you determine the answer to the original question for yourself. The script assumes you have the latest version of the CLI (2.17 at the time of writing) and that you have already logged in (az login) and selected an appropriate subscription. You might for example run this script in Azure Cloud Shell.

# A valid password requires a length of 12 and at least one upper/lower/digit
# Generate a random string of 12 characters to make the names unique and to use as a password
while ! echo $random12 | grep -P "(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).*"
random12=$(head /dev/urandom | tr -dc a-zA-Z0-9 | fold -w 12 | head -n 1)
# Create a new resource group for this test
az group create -n $group -l $region
# Don't do this in real life, where the password equals part of the VM name
# Let the command create a new VNET, we're deleting it shortly anyway
az vm create -g $group -l $region -n $vm1name –admin-password $random12 \
–admin-username azureuser –authentication-type password \
–image UbuntuLTS –public-ip-address ""
diskId=$(az vm show -g $group -n $vm1name -o tsv –query "{ }")
# Create a snapshot
az snapshot create -g $group -n "$vm1name-ss" –source $diskId
# Delete the VM
az vm delete -g $group -n $vm1name –yes
# Delete the disk
az disk delete –id $diskId –yes
# Find the snapshot (yes, it's still there)
az snapshot show -g $group -n "$vm1name-ss"
# Clean up: delete the whole RG
az group delete -n $group –yes

Note: When you delete a VM, it doesn’t automatically delete associated Azure resources. Commonly, I see Azure administrators forgetting about the disk, the network interface card (NIC), and the public IP (if there is one). Be sure to clean up those orphaned resources!

*: I am a big fan of Azure Image Builder (AIB) and automating the image build process. However, AIB is still in preview and most customers also weren’t mature enough to attempt that approach.

Let me know what you think, or ask a question...

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.