There are occasions where we need to move Azure Virtual Machines from one resource group to another. In this post, I am going to demonstrate how we can do that. Before start, there are a few things we should look in to.
• Not every resource can move from one resource group to another. More info about it can find under https://docs.microsoft.com/en-gb/azure/azure-resource-manager/move-support-resources
• If you are looking to move from one region to another, there is a separate process for that. I already wrote an article about it. You can access it using, https://www.rebeladmin.com/2019/11/step-step-guide-move-azure-vm-one-region-another/
• When you move resources, make sure to migrate all dependencies with it.
• When a virtual machine is moved from one resource group to another, the system creates a new resource ID. If you use this value on scripts or other services, those will need to update after the move.
• The same method also can use to move resources from one subscription to another.
In this demo, I am going to create a new VM in one resource group and then move it to another.
For the configuration process, I will be using PowerShell. Therefore, please make sure you have an Azure PowerShell module installed. More info about it can find under https://docs.microsoft.com/en-us/powershell/azure/install-az-ps?view=azps-2.6.0
1. Launch PowerShell console and connect to Azure using Connect-AzAccount
2. Then create two new resource group using,
New-AzResourceGroup -Name REBELRG1 -Location "East US"
New-AzResourceGroup -Name REBELRG2 -Location "East US"
In the above, REBELRG1 & REBELRG2 are the resource group names and East US is the resource group location.
3. The next step is to create a new virtual network under REBELRG1 resource group.
$vmsubnet = New-AzVirtualNetworkSubnetConfig -Name vmsubnet -AddressPrefix "10.0.2.0/24"
New-AzVirtualNetwork -Name REBELVN1 -ResourceGroupName REBELRG1 -Location "East US" -AddressPrefix "10.0.0.0/16" -Subnet $vmsubnet
In the above, REBELVN1 is the new virtual network name. It has 10.0.0.0/16 address space. It also has a new subnet 10.0.2.0/24 (vmsubnet) for virtual machines. [Read more…] about Step-by-Step Guide: How to Move Azure VM to a different Resource Group? (PowerShell Guide)