Create a new VM on a new storage account from a custom image
This Terraform template was based on this Azure Quickstart Template. Changes to the ARM template that may have occurred since the creation of this example may not be reflected here.
This template allows you to create a new Virtual Machine from a custom image on a new storage account deployed together with the storage account, which means the source image VHD must be transferred to the newly created storage account before that Virtual Machine is deployed. This is accomplished by the usage of a transfer virtual machine that is deployed and then uses a script via custom script extension to copy the source VHD to the destination storage account. This process is used to overcome the limitation of the custom VHD that needs to reside at the same storage account where new virtual machines based on it will be spun up, the problem arises when you are also deploying the storage account within your template, since the storage account does not exist yet, how can you add the source VHDs beforehand?
Basically, it creates two VMs, one that is the transfer virtual machine and the second that is the actual virtual machine that is the goal of the deployment. Transfer VM can be removed later.
The process of this template is:
- A Virtual Network is deployed
- Virtual NICs for both Virtual Machines
- Storage Account is created
- Transfer Virtual Machine gets deployed
- Transfer Virtual Machine starts the custom script extension to start the VHD copy from source to destination storage acounts
- The new Virtual Machine based on a custom image VHD gets deployed
- A preexisting generalized (sysprepped) Windows image. For more information on how to create custom Windows images, please refer to How to capture a Windows virtual machine in the Resource Manager deployment model article.
- Source image blob full URL. e.g. https://pmcstorage01.blob.core.windows.net/images/images/Win10MasterImage-osDisk.72451a98-4c26-4375-90c5-0a940dd56bab.vhd. Note that container name always comes after https://pmcstorage01.blob.core.windows.net, in this example it is images. The actual blob name is images/Win10MasterImage-osDisk.72451a98-4c26-4375-90c5-0a940dd56bab.vhd.