March 20, 2017

ARM Templates and Managed Disks

One of the most exciting features to come out of Azure Storage of late is the introduction of Managed Disks. If you are not familiar with the glory of this tool, please see here. In a nutshell, Managed Disks takes away all the pain of managing the underlying Azure Storage Account and lets you, dear user, focus on what's really important - getting things deployed! No more working with iops limits, no more dealing with max number of VHDs per storage account, storage account throttling, etc. Horray you say? Yes indeed, horray.

Next up, was what to do with them. I, like many of you, prefer to automate all of the things. There are a variety of great ways to automate and configure VM deployments with Managed Disks and the CLI, but something that was missing was the ability to do Managed Disks + Custom Image + ARM Template + Scale Sets deployment. Well, to be honest, it isn't missing, it's right there, just not at all documented yet. So here I am, your humble servant to provide the goodness that is the above scenario.

First, some references that helped me along the way.

  1. How do you work with Scale Sets in Managed Disks. Link
  2. How do you convert EXISTING ARM Templates to use Managed Disks. Link (I love reading pull requests haha)
  3. How do you create a generalized VM and capture it when you are using a Managed Disk (hint, it's not that different). Link
  4. I decided to make this fun, so I did it all with the new Azure CLI 2.0. Here are some of the changes I needed to make to my thinking. Link
  5. The mother load of all that is good with Managed Disks, along with a few gaps that need to be filled. Link

Ultimately, I needed just a few extra bits to make things go, but banged my head against the wall for a number of hours getting it all lined up. Here's where I landed:

  1. Get a VM in managed disks sysprepped / ready for capture. In my case, I used Premium Disks so when it is captured as an Image, it is Premium, so you can only deploy a Premium VM as a result.
  2. Once you have the VM shutdown, capture the VM as an image using the tool of your choice. Me, I just hit the CAPTURE button in the portal.
  3. Once captured, I had a disk image!
  4. Next, it was time to create and deploy my ARM template.

And here is the completed template: link

The key to this template is the line down on OSDisk that references the image. Remember, in managed disks, my image can be anywhere in the same subscription!!!

"id": "/subscriptions//resourceGroups//providers/Microsoft.Compute/images/"

That did the trick - a quick template deployment later and I had 1000 VMs running my custom Windows image.