Deploying VM’s into a storage account has always been the norm, but now with the release of Managed Disks, it takes all the hard work away with a simplified management solution.

You’re probably like me and first wondered “I’ve got hundreds of templates with Storage Accounts, how can i change them to managed disks”

Well the answer is “pretty damn easy”

In your JSON template, scroll down to your VM

Below is a small part of JSON which reflects on how it was previously authored

          "osDisk": {

            "name": "[variables('VM01OSDiskName')]",

            "vhd": {

              "uri": "[concat('http://', parameters('StorageAccountName01'), '.blob.core.windows.net/', variables('stdVHDContainerName'), '/', variables('VM01OSDiskName'), '.vhd')]"

            },

            "caching": "ReadWrite",

            "createOption": "FromImage"

          }

Before we dive into this, there is one key thing you need to change on your VM script block, before you write the Managed Disk part.
The API will need to be changed to the below preview version

 "type": "Microsoft.Compute/virtualMachines",

 "apiVersion": "2016-04-30-preview",

Believe it or not, changing the syntax for managed disk is relatively straight forward

You remove the “vhd” “uri” and “caching” section, which will leave you with this

 

"osDisk": {

 "name": "[variables('VM01OSDiskName')]",

 "createOption": "FromImage"

 } 

We then need to add the “managedDisk” syntax into your script block

 

 "osDisk": {

 "name": "[variables('VM01OSDiskName')]",

 "managedDisk": {

 "storageAccountType": "Standard_LRS"

 },
 "createOption": "FromImage"
 }
 },

And that ladies and gentlemen that is it….But i hear you whisper in the background, what about availability sets?

Below is a before (as in, your original template) of what your current Availability Set looks like


{
"name": "[Parameters('availabilitySet01')]",
"type": "Microsoft.Compute/availabilitySets",
"location": "[resourceGroup().location]",
"apiVersion": "2015-06-15",
"tags": {
},
"properties": {
"platformUpdateDomainCount": 1,
"platformFaultDomainCount": 1
}
}

So for Availability Sets to work with the new Virtual Machine Managed Disks, we need to adjust our script block

Below is the NEW script, and you’ll see that there’s only two additional lines of code “sku” and the “name”:Aligned”

If the SKU isn’t passed, then it will proceed as Classic, and ultimately fail, and spit out a hideous error message

By adding the SKU and value “aligned” (don’t forget to change the API to “2016-04-30-preview” ) this will deploy your Availability set with your two virtual machines (or however many you have)


{
"name": "[Parameters('availabilitySetName')]",
"type": "Microsoft.Compute/availabilitySets",
"location": "[resourceGroup().location]",
"apiVersion": "2016-04-30-preview",
"sku": {
"name": "Aligned"
},
"tags": {
},
"properties": {
"platformUpdateDomainCount": 1,
"platformFaultDomainCount": 1
}
},

Don’t forget to remove your Storage Account resource and whatever parameters or variables you’re referencing too it

I have built this into a 2 VM Deployment Template, if anyone would like this, just drop a message with your email below

Advertisements