If you worked with Azure for a long time, you know that when you wanted to upload your own custom VM image to Azure, it was an easy thing. You prepared the VM, you sent it to Azure using PowerShell and after that you tagged it as an OS disk and that was it. Well that was the old way using the Azure Service Manager which I must say it was quite an easy procedure. With Azure Resource Manager, things changed quite a bit. You still have the possibility of uploading the VHDs to Azure but the deployment requires a little more work. You have to write code for that deployment to happen, be it in PowerShell or JSON. In this blog post I’m going to give you two ARM templates which you can use to deploy your freshly uploaded VHDs.

While I like PowerShell very much and I use non-stop for everything, Azure Resource Manager makes writing PowerShell for deploying and managing stuff a bit harder. Not impossible but harder, so here I am, writing JSON code for deploying and managing resources in Azure and boy let me tell you that it’s going to take a while till you get the hang of them, and the earlier you start understanding how ARM templates, the better.

At this point in time, there’s no easy way in writing these ARM Templates. We have the possibility of using Visual Studio paired with the Azure SDK, which can give you a kick in the right direction but it will not help a lot because it’s kinda outdated. So the best way to create these ARM templates is by using other available templates and adapt them to your needs. You can get all the examples that you want from the Microsoft Azure Github repo – Azure ARM Templates

In the Azure Github repository there are two examples that you can use to create a VM from a specialized image, but those templates just shows you how it works and they can’t be used for production deployments without doing some work.

The templates attached to this blog post will allow you to create a Windows or Linux VM using a VHD that was uploaded into an Azure Storage Account. Please note that at this time, you cannot have a “golden image” in a separate Storage Account due to an Azure limitation. There is a feedback post about this issue which unfortunately is under review for a while, and I hope that this will be solved soon™.

In order to use these templates, you need to have the .vhd of a deprovisioned Linux or sysprepped Windows virtual machine in a Storage Account and you need the URI of the VHD that will be used for the deployment.

You can get the URI of your uploaded VHD(s) by using the following Azure PowerShell script:

Now that you have everything set, all you need to do is to start deploying 🙂

The templates attached in this blog post cover two scenarios and are adapted for when that Azure limitation is lifted so you can have your golden image in a separate storage account.

Scenario 1:


Scenario 2:


The first template deploys a new VM based on that specialized image that you have uploaded, and it creates a Public Dynamic IP, Virtual Network and Network Security Group with RDP / SSH access. The second template covers the scenario where you already have a some virtual machines deployed in a Resource Group and in a Virtual Network, and you want to deploy one or more VMs from that specialized VHD that you uploaded. The difference between the first and second one is that in the second one has mandatory parameters where you need to specify the existing Virtual Network and in which subnet you want the new VM to be deployed in.

Now at this point, all you need to do is to copy the templates and use them either in the portal as a Template Deployment, or save the contents in a .json file and deploy them using PowerShell.

I for one prefer the PowerShell way so here’s the PowerShell script that you can use to deploy the .json templates:

In the end, ARM Templates may look scary at first but once you take the time and analyze them, you will notice that they aren’t any big deal at all. So my advice to you is; Look at the examples in the Azure GitHub repo and start small.

That’s it, have a good one!

Privacy Preference Center

    Pin It on Pinterest