Azure ARM Template to deploy a new VM in a new storage account deployed at same time from a custom image
At the beginning of this year I had a simple ask from a customer, how do we deploy a virtual machine from a custom image using ARM Templates? This is easily done if the custom image already resides in the same storage account where your virtual machines based on that will be deployed, but what happens if you don’t have it before the deployment time? Then I decided to share this with as many customers as possible, so created this Azure Resource Manager (ARM) template and had it published on GitHub Azure Quick Start Templates repository that helps customers deploy a new virtual machine from a custom image with a new storage account at the same time.
The challenge here is that for many Dev/Test environments we use ARM Templates to deploy environments really quick to perform testing, destroy it, go back to fix bugs, deploy it again and so on.
That environment will always have a new storage account and to be able to deploy (at the moment that this blog and template was posted) that custom image must reside in the same storage account where your virtual machines will be deployed. So the question is, how do I do that if I don’t have the storage account beforehand?
The solution to that is this template that uses what we call a transfer virtual machine that basically contains a script that will copy the source custom image virtual hard disk (VHD) to the newly deployed storage account, then the template starts deploying the virtual machines that uses this VHD as its image (instead of an image from Azure Marketplace).
The GitHub template main page shows you how to perform the deployment, basically it is done from Powershell, can be done from Cross Platform Command Line Interface too but I didn’t add the steps for that there (I may update this post with this option later).
You can access this template from this links
Create VM from a custom image in new storage account (if you click Learn more on GitHub you get directed to the GitHub page of the template where has more information on how to deploy it)
That’s it for this post, hope that this helps as a stating point for great environments deployed using Azure ARM Templates.