How to create a proximity placement group after VM and disks have been created?

201 Views Asked by At

I have created 2 VMs and couple of disks.

Some of these disks are shared disks (part of wsfc cluster), and some disks are non-shared.

I want to add all the VMs and disks into a proximity placement group.

How to create a proximity placement group after VM and disks have been created?

1

There are 1 best solutions below

7
Venkat V On

I want to add all the VMs and disks into a proximity placement group.

You cannot add Azure Disks to an Azure proximity placement group as it is designed to group Azure compute resources such as Virtual Machines and Virtual Machine Scale Sets.

An Proximity Placement Group is primarily used to logically group Azure compute resources that are physically located in close proximity within the data center. This grouping aims to reduce latency and improve application performance. Here is the MS Doc about Proximity Placement Groups.

For adding multiple VMs to Proximity Placement Groups at once, you can use PowerShell.

Here is a PowerShell script to add existing VMs to Proximity Placement Groups

    $resourceGroup = "venkattests-resources"
    $location = "West Europe"
    $pgname = "sampleProximitygroup"
    $zone = "1"
    $vmsize1 = "Standard_E64s_v4"
    $vmsize2 = "Standard_M416ms_v2"
    $ppgn = New-AzProximityPlacementGroup -Location $location -Name $pgname -ResourceGroupName $resourceGroup -ProximityPlacementGroupType Standard -Zone $zone -IntentVMSizeList $vmsize1, $vmsize2
    $vms = Get-AzVM -ResourceGroupName $resourceGroup
    
    foreach ($vm in $vms) {
    
        # Stop the VM before making changes
        Stop-AzVM -ResourceGroupName $resourceGroup -Name $vm.Name -Force
    
        # Update the VM with the Proximity Placement Group
         $vm.ProximityPlacementGroup = $ppgn.Id
    
        Write-Host "Adding VM: $($vm.Name) with Proximity Placement Group: $($ppgn.Name)"
    
        Update-AzVM -ResourceGroupName $resourceGroup -VM $vm
    
         Write-Host "Updated VM: $($vm.Name) with Proximity Placement Group: $($ppgn.Name)"
    
        # Start the VM again
    
        Start-AzVM -ResourceGroupName $resourceGroup -Name $vm.Name
    
    }

Result:

enter image description here

All VMs in the resource group have been added to the Proximity Placement Group

enter image description here

Reference: Add existing VM to placement group