Migrate IaaS from Classic to Azure Resource Manager (PowerShell)

In Azure we have two deployment methods, ASM (Azure Service Manager) aka classic & ARM (Azure Resource Manager). When the beginning of Azure we use ASM model to deploy resources and manage our cloud infrastructure but soon Azure team realize we need a better more robust management and deployment infrastructure for azure. So beginning of 2015 they introduce the new model ARM and gradually they migrate resources support from ASM to ARM. But the question we face is how we migrate resources we deployed in to ASM to ARM, we just can’t migrate them because both are two separate models and have different API calls. So from today’s post I’ll walk-through how we can migrate IaaS infrastructure from ASM to ARM.

Before migrating resources refer supported and unsupported features and configurations to verify which resources are support for migration.

So first step is to login to Azure ARM & ASM model using PowerShell

<br />
#Login Azure ARM<br />
Login-AzureRmAccount</p>
<p>#Login Azure ASM<br />
Add-AzureAccount </p>
<p>#Select Azure Subscription<br />
Select-AzureRmSubscription -SubscriptionId &lt;SubscriptionID&gt;<br />
Select-AzureSubscription -SubscriptionId &lt;SubscriptionID&gt; -Current<br />

Next we had to register the migration resources for migration

<br />
#Register Migration Resources<br />
Register-AzureRmResourceProvider -ProviderNamespace Microsoft.ClassicInfrastructureMigrate</p>
<p>#Verify Migration Resources are registered<br />
Get-AzureRmResourceProvider -ProviderNamespace Microsoft.ClassicInfrastructureMigrate<br />

After register the resource wait for five minutes to complete the registering, if its success it shows as bellow

In this post migrating a virtual machine that attached to VNET if you’re migrating any other resource(cloud service) refer this documentation.

The easiest way to migrate a VM attached in to VNET is to migrate the VNET, When we migrate VNET it migrate the VM to the ARM model.

It’s a three-step first we have to validate the resources are valid for migration and it will give any errors or warnings if there any.

<br />
#Migrate VM in a VNET </p>
<p>$vnetName = &quot;asmmig&quot;</p>
<p>#Validate the VNET for Migration<br />
$validateMessage = Move-AzureVirtualNetwork -Validate -VirtualNetworkName $vnetName</p>
<p>[12:44:40 PM] KRR C:\&gt; $validateMessage.ValidationMessages</p>
<p>ResourceType : VirtualNetwork<br />
ResourceName : asmmig<br />
Category : Information<br />
Message : Virtual Network asmmig is eligible for migration.<br />
VirtualMachineName : </p>
<p>ResourceType : Deployment<br />
ResourceName : web01<br />
Category : Information<br />
Message : Deployment web01 in Cloud Service asmmigkasun is eligible for migration.<br />
VirtualMachineName : </p>
<p>ResourceType : Deployment<br />
ResourceName : web01<br />
Category : Information<br />
Message : VM web01 in Deployment web01 within Cloud Service asmmigkasun is eligible for migration.<br />
VirtualMachineName : web01</p>
<p>ResourceType : Deployment<br />
ResourceName : web01<br />
Category : Warning<br />
Message : VM web01 in HostedService asmmigkasun contains Extension BGInfo version 1.* which is an<br />
 XML extension. XML extensions are not supported in Azure Resource Manager. It is<br />
 recommended to uninstall it from the VM. Alternatively, it will be automatically<br />
 uninstalled during migration.<br />
VirtualMachineName : web01<br />

Next we have to prepare for migration

<br />
#Prepare for migration<br />
$prepareMessage = Move-AzureVirtualNetwork -Prepare -VirtualNetworkName $vnetName<br />

When this command execute you will see resources are moving from ASM to ARM as follows

In this it only migrate VM and VNET only we have to migrate Storage account separately.

Next we have to commit the migration

<br />
#commit the Migration<br />
$commitMessage = Move-AzureVirtualNetwork -Commit -VirtualNetworkName $vnetName<br />

Next we need to migrate the storage from ASM to ARM

Before migrating we need to few prerequisites to verify the VM disks are moved

<br />
#Migrate Storage Account ------------------------------------------------------------------------------------</p>
<p>#Prerequist Checks</p>
<p>$storageAccountName = 'armmig'<br />
Get-AzureDisk | where-Object {$_.MediaLink.Host.Contains($storageAccountName)} | Select-Object -ExpandProperty AttachedTo -Property `<br />
DiskName | Format-List -Property RoleName, DiskName</p>
<p>#Delete Unattached classic VM disk in storage Account (If Exists from above command)<br />
$classicVMDiskName = Get-AzureDisk | where-Object {$_.MediaLink.Host.Contains($storageAccountName)} | Format-List -Property DiskName<br />
Remove-AzureDisk -DiskName 'DiskName'</p>
<p>#Delete VM Images<br />
Get-AzureVmImage | Where-Object { $_.OSDiskConfiguration.MediaLink -ne $null -and $_.OSDiskConfiguration.MediaLink.Host.Contains($storageAccountName)} | Select-Object -Property ImageName, ImageLabel<br />
Remove-AzureVMImage -ImageName 'yourImageName' #If output from above command<br />

Next we have to repeate the same steps as VNET migration

<br />
#prepare moving storage account<br />
$prepareStorageMsg = Move-AzureStorageAccount -Prepare -StorageAccountName $storageAccountName</p>
<p>#commit the storage migration<br />
$commitStorageMsg = Move-AzureStorageAccount -Commit -StorageAccountName $storageAccountName<br />

After this commands you will see the storage account is migrated to ARM as bellow

Now you can see resources are in 3 resource groups so its little hard to manage when same infrastructure resources are in different RG so we can move those resources to one RG as follows.

After move we can see as below.

 

, , , , , , ,

Post navigation