February 19, 2018

Microsoft Azure - Migrate from classic to ARM

In this post I show how to migrate supported IaaS resource from classic deployment model to Azure Resource Manager. PowerShell will be used to achieve this task. Make sure that you are an administrator for your Azure subscription and your Azure region has enough available vCPUs resources (refer to ARM limits).

Items for migration:
TestRG1 - Virtual network (classic)
Testrg1sa - Storage account (classic)
TestVm1 - Virtual machine (classic)
TestVM19796 - Cloud service (classic)

1. Install Azure PowerShell command-line tools from Microsoft Azure download page - https://azure.microsoft.com/en-us/downloads/ It is used for managing classic resources.

2. Install Azure PowerShell to manage ARM resources by running command below.
PS C:\> Install-Module -Name AzureRM -AllowClobber

3. Login to ARM.
PS C:\> Login-AzureRmAccount


Account          : admin@example.com
SubscriptionName : Your Azure Subscription Name
SubscriptionId   : xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
TenantId         : xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Environment      : AzureCloud
You will be asked for Azure Credentials. 
 
4. Select Azure subscription. Can be done by command below if you have only one subscription. Refer to Select-AzureRmSubscription cmdlet.
PS C:\> Get-AzureRmSubscription | Select-AzureRmSubscription


Name             : [admin@example.com, xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Account          : admin@example.com
SubscriptionName : Your Azure Subscription Name
TenantId         : xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Environment      : AzureCloud

5. Register migration resource provider. It is one-time operation. Make sure that RegistrationState is Registered before any migration.
PS C:\> Register-AzureRmResourceProvider -ProviderNamespace Microsoft.ClassicInfrastructureMigrate


ProviderNamespace : Microsoft.ClassicInfrastructureMigrate
RegistrationState : Registered
ResourceTypes     : {classicInfrastructureResources}
Locations         : {East Asia, Southeast Asia, East US, East US 2...}

6. Login to Azure classic. You will be asked to provide the credentials as on step #3.
PS C:\> Add-AzureAccount

Id              : admin@example.com                               
Type            : User
Subscriptions   : xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx                   
Tenants         : xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx                    

7. Select Azure subscription by running command below. List of available subscriptions can be found by running Get-AzureSubscription cmdlet.
PS C:\> Select-AzureSubscription -SubscriptionName "Your Azure Subscription Name"

8. Find out Virtual network name and put it into variable.
PS C:\> (Get-AzureVnetSite).Name
Group TestRG1 TestRG1

PS C:\> $vnetName = "Group TestRG1 TestRG1"

9. Validate if you are eligible to migrate the virtual network. Make sure that Validation Passed. As you can see all resources except Storage account are selected for migration.
PS C:\> Move-AzureVirtualNetwork -Validate -VirtualNetworkName $vnetName

OperationId        : xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Result             : Validation Passed. Please see ValidationMessages object for a list of resources that will be migrated.
ValidationMessages : {Group TestRG1 TestRG1, TestVM19796, TestVM19796}

10. Prepare for Virtual network migration. Operation status should be Succeeded.
PS C:\> Move-AzureVirtualNetwork -Prepare -VirtualNetworkName $vnetName


OperationDescription     OperationId                          OperationStatus
--------------------     -----------                          ---------------
Move-AzureVirtualNetwork xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx Succeeded      

11. By default after preparation step is completed the following resources are created in Azure Portal divided by 2 Resource groups: TestVM19796-Migrated (Virtual Machine, Key vault, Public IP address, Load balancer and Network interface) and Group-TestRG1-TestRG1-Migrated (Virtual network). 
 
12. At this stage you can check created resources and configurations. There are two options: Abort and Commit. First parameter will revert configuration to the old state and removes all created ARM resources. Commit parameter will write the changes and remove classic resources from Azure portal.
PS C:\> Move-AzureVirtualNetwork -Commit -VirtualNetworkName $vnetName


OperationDescription     OperationId                          OperationStatus
--------------------     -----------                          ---------------
Move-AzureVirtualNetwork xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx Succeeded      

13. After Commit operation is completed, classic resources will be removed from Azure Portal. Only Storage account left at this stage.
14. Next migrate Storage account. Check if you are ready for migration by Validate step.
PS C:\> Move-AzureStorageAccount -Validate -StorageAccountName "SA Name"

OperationId        : xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Result             : Validation Passed. Please see ValidationMessages object for a list of resources that will be migrated.
ValidationMessages : {testrg1sa}

15. Prepare Storage account migration.
PS C:\> Move-AzureStorageAccount -Prepare -StorageAccountName "SA Name"

OperationDescription     OperationId                          OperationStatus
--------------------     -----------                          ---------------
Move-AzureStorageAccount xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx Succeeded
You will see 2 entries in Azure Portal.

16. Finalize storage account migration by Commit parameter.
PS C:\> Move-AzureStorageAccount -Commit -StorageAccountName "SA Name"

OperationDescription     OperationId                          OperationStatus
--------------------     -----------                          ---------------
Move-AzureStorageAccount xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx Succeeded     

No comments:

Post a Comment