Moving a VM from one VNet to another in Azure

I had to move a VM from one VNet to another VNet, the first idea I had was to attach another NIC from the different VNet to the VM, making that primary and then removing the older NIC.

But when I checked that option in the portal adding for attaching a network interface got a bummer as the new NIC should be in the same VNet as the primary one.

Error adding another NIC

To move the VM from one VNet to another VNet, you have two possible options:

  1. Create a snapshot of the VM disk and create another VM using that disk snapshot. Check this blog on how to do that.

2. Delete the VM and not the Disk and use this disk to create another VM.

STEP 1: Deleting the resources

The VM ‘test’ is currently on vnet1.

Current VM VNet

The first thing to do is deallocate the VM only, leaving it’s disk behind.

Current resources

The resources that are created are VM, NSG (if you have one-to-one mapping of VM and NSG) and the NIC.

STEP 2: Creating another VM

To create a VM using the left out disks, choose the OsDisk and select Create VM.

Create VM from the disk

After providing the name and size options in the first tab, you can add the additional disk in the disks tab and choose the network in the third. Previously the VM was in vnet1 now I will be creating it in VNet2

Choose the new network.

To summarize

If you need to move the VM from one VNet to another there is no direct way but this can still be done using the underlying storage for the VM.

One thought on “Moving a VM from one VNet to another in Azure

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s