|
| 1 | +--- |
| 2 | +title: Migrate Managed image to Compute gallery |
| 3 | +description: Learn how to legacy Managed image to image version in Azure compute gallery. |
| 4 | +author: AjKundnani |
| 5 | +ms.service: virtual-machines |
| 6 | +ms.subservice: gallery |
| 7 | +ms.topic: how-to |
| 8 | +ms.date: 03/09/2024 |
| 9 | +ms.author: ajkundna |
| 10 | +ms.reviewer: cynthn |
| 11 | +ms.custom: template-how-to, devx-track-azurepowershell |
| 12 | +--- |
| 13 | + |
| 14 | +# Migrate Managed image to Azure compute gallery image version |
| 15 | + |
| 16 | +**Applies to:** :heavy_check_mark: Linux Virtual Machine :heavy_check_mark: Windows Virtual Machine :heavy_check_mark: Virtual Machine Flex Scale Sets |
| 17 | + |
| 18 | +[Managed images](capture-image-resource.md) is legacy method to generalize and capture Virtual Machine image. For the most current technology, customers are encouraged to use [Azure compute gallery](azure-compute-gallery.md). All new features, like ARM64, Trusted launch, and Confidential Virtual Machine are only supported through Azure compute gallery. If you have an existing managed image, you can use it as a source and create an Azure compute gallery image. |
| 19 | + |
| 20 | +## Before you begin |
| 21 | + |
| 22 | +- [Create an Azure Compute Gallery](create-gallery.md). |
| 23 | +- Assign `Reader` permission on source managed image. |
| 24 | +- Assign `Contributor` permission on target Azure compute gallery image definition. |
| 25 | + |
| 26 | +## Migrate Managed image to Azure Compute Gallery image |
| 27 | + |
| 28 | +### [Portal](#tab/portal) |
| 29 | + |
| 30 | +This section steps through using the Azure portal to migrate Managed image to existing Azure Compute Gallery. |
| 31 | + |
| 32 | +1. Sign-in to [Azure portal](https://portal.azure.com). |
| 33 | +2. Navigate to `Managed image` to be migrated and select **Clone to a VM image**. |
| 34 | + |
| 35 | +:::image type="content" source="./media/shared-image-galleries/01-click-clone-image.png" alt-text="Screenshot of the Managed image to be migrated"::: |
| 36 | + |
| 37 | +3. Provide following details on the `Create VM image version` page and select **Next : Replication >**: |
| 38 | + - Version number |
| 39 | + - Target Azure compute gallery |
| 40 | + - Target Virtual Machine image definition |
| 41 | + |
| 42 | +4. Select following `Replication` configuration or select default values and select **Next : Encryption >**: |
| 43 | + - Default storage sku |
| 44 | + - Default replication count |
| 45 | + - Target replication regions |
| 46 | + |
| 47 | +5. Select `SSE encryption type` or select default `Encryption at-rest with a platform managed key` and select **Next : Tags >**. |
| 48 | +6. *Optional* Assign resource tags. |
| 49 | +7. Validate the configuration on `Review + Create` page and select **Create** to complete the migration. |
| 50 | + |
| 51 | +### [CLI](#tab/cli) |
| 52 | + |
| 53 | +You need the `tenantID` of the source image, the `subscriptionID` for the Azure compute gallery (target), and the `resourceID` of the source image. |
| 54 | + |
| 55 | +```azurecli |
| 56 | +# Set some variables |
| 57 | +tenantID="<tenant ID for the source image>" |
| 58 | +subID="<subscription ID where the image will be creted>" |
| 59 | +sourceImageID="<resource ID of the source managed image>" |
| 60 | +
|
| 61 | +# Login to the subscription where the new image will be created |
| 62 | +az login |
| 63 | +
|
| 64 | +# Log in to the tenant where the source image is available |
| 65 | +az login --tenant $tenantID |
| 66 | +
|
| 67 | +# Log back in to the subscription where the image will be created and ensure subscription context is set |
| 68 | +az login |
| 69 | +az account set --subscription $subID |
| 70 | +
|
| 71 | +# Create the image |
| 72 | +az sig image-version create ` |
| 73 | + --gallery-image-definition myImageDef ` |
| 74 | + --gallery-image-version 1.0.0 ` |
| 75 | + --gallery-name myGallery ` |
| 76 | + --resource-group myResourceGroup ` |
| 77 | + --image-version $sourceImageID |
| 78 | +``` |
| 79 | + |
| 80 | +### [PowerShell](#tab/powershell) |
| 81 | + |
| 82 | +You need the `tenantID` of the source image, the `subscriptionID` for the Azure compute gallery (target), and the `resourceID` of the source image. |
| 83 | + |
| 84 | +```azurepowershell |
| 85 | +# Set variables |
| 86 | +$targetSubID = "<subscription ID for the target>" |
| 87 | +$sourceTenantID = "<tenant ID where for the source image>" |
| 88 | +$sourceImageID = "<resource ID of the source image>" |
| 89 | +
|
| 90 | +# Login to the tenant where the source image is published |
| 91 | +Connect-AzAccount -Tenant $sourceTenantID -UseDeviceAuthentication |
| 92 | +
|
| 93 | +# Login to the subscription where the new image will be created and set the context |
| 94 | +Connect-AzAccount -UseDeviceAuthentication -Subscription $targetSubID |
| 95 | +Set-AzContext -Subscription $targetSubID |
| 96 | +
|
| 97 | +# Create the image version from another image version in a different tenant |
| 98 | +New-AzGalleryImageVersion ` |
| 99 | + -ResourceGroupName myResourceGroup ` |
| 100 | + -GalleryName myGallery ` |
| 101 | + -GalleryImageDefinitionName myImageDef ` |
| 102 | + -Location "West US 2" ` |
| 103 | + -Name 1.0.0 ` |
| 104 | + -SourceImageId $sourceImageID |
| 105 | +``` |
| 106 | + |
| 107 | +## Next steps |
| 108 | + |
| 109 | +Replace managed image reference with Azure compute gallery image version in the Virtual machine and flex scale sets deployment templates. |
0 commit comments