How to copy azure disk from one location to another just by using terraform

1.4k views Asked by At

The challenge is to have a way to copy osdisk and datadisk from vm located in first location, to another one and of course spawn there a new virtual machine.

So far I found disks-upload-vhd-to-managed-disk-cli article and was able to copy disk between different location by using azcopy utility and creating sas uri links.

As I use terraform everywhere I don't like to use external tools for such job.

I try already abuse azurerm_managed_disk to be able make a copy of my disk to another location but it seams that it's not possible, and those disk need to be in the same place.

So maybe some of you have idea how to make such copy of the disks (or entire vm) in different location just by terraform way and of course I don't mean here to use local-exec to wrap azcopy in it :)

Best Regards.

1

There are 1 answers

0
Charles Xu On

To copy the managed disk to another region, except the AzCopy command, you can only copy the disk with a generated SAS URL into a storage page blob in another region. And then create a managed disk from the VHD file in that storage blob.

The steps here:

  1. export the disk that you want to copy and then it will generate a SAS URL;
  2. create a storage page blob in the storage container which in the target region from the SAS URL;
  3. create a managed disk from the page blob in the same region.