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
Follow @CraigCloudITPro
Hey Craig,
Thanks for posting this article. It’s one of the only articles I’ve been able to find online regarding ARM templates and managed disks. You wrote in your article if anyone wanted a copy of the template you created to drop a line in the comment section. I was wondering if you’d mind sharing your template with me? I’m trying to create a template that simply deploys two standard (no custom image) Server 2016 VMs with managed disks, and places them in an existing Vnet and subnet. I’m not really so worried about availability sets and stuff, just creating two VMs with managed disks. If you could share your template I think that may help me out.
Thanks!
Jim
LikeLike
Hi Jim, not a problem at all 🙂 What’s your email address and I’ll send you a template across
LikeLike
Hi Jim,
I am trying to deploy vm from custom image which is available as managed disk. But I am getting error. Could u please send the template to this email address
keerthikrishnan1369@gmail.com
LikeLike
Craig great post thank you very much. This has helped me get my templates updated. I am however running into an issue I was curious if you have ever seen before. I am trying to redeploy a VM that was originally created with non-managed disks that post deployment was converted to managed disks. I am receiving the following error and was wondering if you had seen before.
New-AzureRmResourceGroupDeployment : 8:48:58 PM – Resource Microsoft.Compute/virtualMachines
‘acusnmpgciusq1’ failed with message ‘{
“error”: {
“code”: “PropertyChangeNotAllowed”,
“target”: “dataDisk.name”,
“message”: “Changing property ‘dataDisk.name’ is not allowed.”
}
I would be more than happy to share my code offline.
Thanks again!
LikeLiked by 1 person
Hi Matthew, thanks for commenting, if you add me on LinkedIn, I can assist you from there 🙂
https://www.linkedin.com/in/craig-fretwell/
Craig
LikeLike