Azure ARM Template to deploy a new VM in a new storage account deployed at same time from a custom image


Hi Everyone,

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)

Direct link: https://github.com/Azure/azure-quickstart-templates/tree/master/201-vm-custom-image-new-storage-account

 

That’s it for this post, hope that this helps as a stating point for great environments deployed using Azure ARM Templates.

Comments (4)

  1. John Garland says:

    Thank you Paulo – I was running into exactly this. I’d run into this quickstart template, but was trying to find if there was a better option that didn’t include the extra cost in time and $ related to standing up the “for transfer purposes only” VM as part of the process.

    Which brings me to my question – have you run into any reason/rationale for the “colocation” requirement? At first glance, it seems a bit contrived as far as requirements go. In your research/conversations, have you run into a specific technical limitation it addresses, or otherwise encountered any history behind it?

    1. Hi John,

      Currently there is no other option to deploy a whole new environment, meaning, new storage account and new vm from a custom image because the custom image needs to exist in the same storage account where the VMs based on that image will be created, that’s the only reason. Now, if you have an already stablished storage account with your custom images and you’re deploying VMs in that same storage account, you will not need this template, you can use this other Azure Quick Start template https://azure.microsoft.com/en-us/documentation/templates/201-vm-from-specialized-vhd/.
      Also, after you deployed your custom image based VM you can definitively delete the transfer VM.

      Hope that this helps clarifying a little bit more.

      Regards

      Paulo

      1. John Garland says:

        Thank you Paulo – I follow. My scenario is that I need to use a single Custom Image to deploy VM’s in different Azure Subscriptions. The place where I am confused is the rationale (whatever it may be, from the team responsible) behind “the custom image needs to exist in the same storage account where the VMs…” Why? What part of Azure would be broken if the reference Image and (eventual) VM resided in different Storage Accounts? How do the Marketplace images function so that this is not an issue with them? I didn’t know if you had insight here, or if it is something I should raise on one of the MVP lists. Beyond getting it changed, I’m actually curious.

        There is a UserVoice that was opened about this quite some time ago, which was promoted to “In Progress” almost 18 months ago at https://feedback.azure.com/forums/216843-virtual-machines/suggestions/6399760-vm-created-from-custom-image-should-be-able-to-sel

        1. I hear you, but I was looking at the user voice link you posted and last update on this matter was done by Corey Sanders and if he mentioned that this is being worked this is a great thing, I don’t have any ETA but we should expect improvements in this area.

          In the meanwhile I’m about to modify the template in order for us to be able to deploy both Windows and Linux images from it, stay tuned.

          Regards
          Paulo

Skip to main content