When creating images in Azure, Microsoft's best practice is to store those images in an Azure Compute Gallery. This service provides version control and replicas to allow organizations to easily manage their virtual machine deployments at scale. Images may be useful in one subscription, tenant, or Azure cloud, but customers tend to expand their footprint. For example, compliance requirements or global scaling dictates the need for expanded capacity across multiple Azure clouds, tenants, or subscriptions. While an Azure Compute Gallery allows you to share Image Versions across subscriptions, sharing can impact an Image Version. Questions may arise about cost or utilization. Who in the organization owns the charges for the images? Should one entity within an organization own the charges for that image and its replicas? Will deployments scale well if other entities within your organization run deployments simultaneously? The ability to copy an Azure Compute Gallery Image Version between Azure clouds, tenants, and subscriptions addresses these concerns.
This document is intended primarily for Azure engineers and administrators that are responsible for deployments and operational practices.
This solution will copy an Image Version from a Compute Gallery in one Azure cloud, tenant, or subscription to a Compute Gallery in another Azure cloud, tenant, or subscription.
Deploy a virtual machine using the Image Version in the source Compute Gallery to ensure the image is functional.
There are several factors to consider when migrating an image version such as network capacity, storage capacity, and security. Use the steps below to minimize the time and effort while addressing capacity and security concerns:
Install-Module AZ
Connect-AzAccount -Environment <Azure-Cloud-Name> -Tenant <Tenant-ID> -Subscription <Subscription-ID>
.\Export-AzureComputeGalleryImageVersion.ps1 -ComputeGalleryName <Compute-Gallery-Name> -ComputeGalleryResourceGroupName <Resource-Group-Name> -ImageDefinitionName <Image-Definition-Name> -ImageVersionName <Image-Version-Name>
Disconnect-AzAccount
Connect-AzAccount -Environment <Azure-Cloud-Name> -Tenant <Tenant-ID> -Subscription <Subscription-ID>
.\Import-AzureComputeGalleryImageVersion.ps1 -ComputeGalleryDefinitionName <Image-Definition-Name> -ComputeGalleryName <Compute-Gallery-Name> -ComputeGalleryResourceGroupName <Resource-Group-Name> -ComputeGalleryVersion <Image-Version-Name> -ImageOffer <Image-Offer> -ImagePublisher <Image-Publisher> -ImageSku <Image-SKU> -ImageState <Image-State> -VhdFilePath <File-Path-to-VHD>
Disconnect-AzAccount
Once both scripts have completed without an error, the Image Version will exist in your target Compute Gallery. The script cleans up the Managed Disks that are created as part of the process. To validate the copy of your Image Version, deploy a virtual machine using the Image Version in the target Compute Gallery to ensure the image is functional.
While there are other ways and tools to perform this task, this method is the least risk adverse. If you have any feedback, please leave it below. If you have any suggestions to make the scripts better, please leave an issue on my GitHub repository or submit a pull request with your updates.
Move to Azure efficiently with customized guidance from Azure engineering: FastTrack for Azure – Benefits and FAQ | Microsoft Azure
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.