Azure – You can now move to availability zone for existing virtual machines (preview)

As you may already know, when you create a virtual machine on Azure you can define the availability zone option to configure the virtual machine for availability in case of infrastructure issue within the Azure region where the VM is deployed.

image

Unfortunately, this option was only available during the creation of the virtual machine; once created you could not change this setting.

Also, sometime, the availability zone capability was not yet available in the Azure region and/or the SKU at the time you created the VM.

Well, good news as now you can edit the availability zone setting for existing virtual machines.

You can edit the availability zone option using either the Azure portal or Azure PowerShell/Cli.

  • Using Azure portal

    • Connect to your Azure portal (https://portal.azure.com/) and locate the virtual machine you want to edit the availability zone
    • Looking at the Overview blade, locate the Availability+scaling\Availability zone section to click the Edit button

image

    • After clicking on the Edit button, you can then enable availability zone and define the number of availability zone for the virtual machine; you will have to enable System Assigned Managed Identity at the bottom of the page

image  image

    • Once you have enable the availability zone, Azure will perform some prechecks.

image

    • During the process, the source virtual machine will be temporarily shutdown
  • Using Azure PowerShell

    • Connect to Azure
      • Connect-AzAccount –Subscription “<subscription-id>”
    • Create the target resource group
      • New-AzResourceGroup -Name “<name of the RG>” -Location “<Azure region>”
    • Create a move collection – the MoveType must be RegionToZone and the Location set to the region where the resources undergoing zonal move reside. Resources added to the move collection must be in the same subscription.
      • New-AzResourceMoverMoveCollection -Name “<collection name>”  -ResourceGroupName “<name of the RG>” -MoveRegion “<Azure region>” -Location “<target location>” -IdentityType “SystemAssigned” -MoveType “RegionToZone”
    • Grant access to the managed identity
      • $moveCollection = Get-AzResourceMoverMoveCollection -Name “<collection name>” -ResourceGroupName “<name of the RG>”
      • $identityPrincipalId = $moveCollection.IdentityPrincipalId
      • New-AzRoleAssignment -ObjectId $identityPrincipalId -RoleDefinitionName Contributor -Scope “/subscriptions/<subscription-id>””
      • New-AzRoleAssignment -ObjectId $identityPrincipalId -RoleDefinitionName “User Access Administrator” -Scope “/subscriptions/<subscription-id>”
    • Add virtual machine to the move collection
      • $targetResourceSettingsObj = New-Object Microsoft.Azure.PowerShell.Cmdlets.ResourceMover.Models.Api20230801.VirtualMachineResourceSettings
      • $targetResourceSettingsObj.ResourceType = “Microsoft.Compute/virtualMachines”
      • $targetResourceSettingsObj.TargetResourceName = “<target resource name>”
      • $targetResourceSettingsObj.TargetAvailabilityZone = “<number of availability zone – 1 to 3>”
    • Add source resource
      • Add-AzResourceMoverMoveResource -ResourceGroupName “<name of the RG>” -MoveCollectionName “collection name” –SourceId <ID of the source VM>” -Name “<move collection name>” -ResourceSetting $targetResourceSettingsObj

Leave a Comment

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.