As a new deployment model,ARM deployment model is much more flexible than the classic one.However,since the great architectural divide of this two deployment models , some resources under ASM deployment model is not compatible with the resources deployed by ARM model.
For instance,we can’t migrate VMs deployed by ASM model in classic VNET to ARM VNET directly.And this blog will provide an easy way to do it.
Now,I have two resource groups: ARMDemo and ASMDemo: each of them has a Windows VM and the VM is deployed in a VNET. The resources in first group is deployed by ARM model and the second is under ASM.
At first, let’s get the OS disk VHD URL of ASMvm:
Copy the URL ,later we will use it to create a managed OS disk and then create a ARM VM and put it into a ARM VNET.
Run following PowerShell command to finish the migrate process:
#destination resource group name,in my case the value is the name of ARM resource group $rgName="ARMDemo" #destination vnet name $vnetName ="ARMDemo-vnet" $rg = Get-AzureRmResourceGroup -Name $rgName $location = $rg.Location #create an os disk for former ASM vm,in my case the value is the OS disk VHD URL of ASM VM $sourceUri = 'https://asmdemo2942.blob.core.windows.net/vhds/ASMvm-os-9658.vhd' $osDiskName = 'FormerASMOsDisk' $osDisk = New-AzureRmDisk -DiskName $osDiskName -Disk (New-AzureRmDiskConfig -AccountType PremiumLRS -Location $location -CreateOption Import -SourceUri $sourceUri) -ResourceGroupName $rgName $vnet = AzureRmvirtualNetwork -Name $vnetName -ResourceGroupName $rgName #public ip for former ASM vm $ipName = "FormerASMvmIP" $pip = New-AzureRmPublicIpAddress -Name $ipName -ResourceGroupName $rgName -Location $location -AllocationMethod Dynamic #create nsg for former ASM vm $nsgName = "FormerASMvmNsg" $rdpRule = New-AzureRmNetworkSecurityRuleConfig -Name myRdpRule -Description "Allow RDP" -Access Allow -Protocol Tcp -Direction Inbound -Priority 110 -SourceAddressPrefix Internet -SourcePortRange * -DestinationAddressPrefix * -DestinationPortRange 3389 $nsg = New-AzureRmNetworkSecurityGroup -ResourceGroupName $rgName -Location $location -Name $nsgName -SecurityRules $rdpRule #create nic for former ASM vm and add to default subnet of destination vnet $nicName = "FormerASMvNic" $nic = New-AzureRmNetworkInterface -Name $nicName -ResourceGroupName $rgName -Location $location -SubnetId $vnet.Subnets.Id -PublicIpAddressId $pip.Id -NetworkSecurityGroupId $nsg.Id #define vm size $vmName = "FormerASMvm" $vmConfig = New-AzureRmVMConfig -VMName $vmName -VMSize "Standard_F1s" #add NIC to the vm $vm = Add-AzureRmVMNetworkInterface -VM $vmConfig -Id $nic.Id #add osDisk to the vm $vm = Set-AzureRmVMOSDisk -VM $vm -ManagedDiskId $osDisk.Id -StorageAccountType PremiumLRS -DiskSizeInGB 128 -CreateOption Attach -Windows #create the vm New-AzureRmVM -ResourceGroupName $rgName -Location $location -VM $vm
If this command was successful, you’ll see output like this:
RequestId IsSuccessStatusCode StatusCode ReasonPhrase --------- ------------------- ---------- ------------ True OK OK
Let’s take a look on Portal :
all the resources has been created and former ASM VM has been migrated to ARMDemo-vnet: