Remove a VM association from a capacity reservation group

This article walks you through the steps of removing a virtual machine (VM) association to a capacity reservation group. To learn more about capacity reservations, see the Capacity reservation overview.

Because both the VM and the underlying capacity reservation logically occupy capacity, Azure imposes some constraints on this process to avoid ambiguous allocation states and unexpected errors.

There are two ways to change an association:

  • Deallocate the virtual machine, change the capacity reservation group property, and, optionally, restart the VM.
  • Update the reserved quantity to zero and then change the capacity reservation group property.

Deallocate the virtual machine

The first option is to deallocate the virtual machine, change the capacity reservation group property, and, optionally, restart the VM.

  1. Deallocate the virtual machine:

    PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{virtualMachineName}/deallocate?api-version=2021-04-01
    
  2. Update the VM to remove the association with the capacity reservation group:

    PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{virtualMachineName}/update?api-version=2021-04-01
    

    In the request body, set the capacityReservationGroup property to null to remove the VM association to the group:

     {
    "location": "eastus",
    "properties": {
        "capacityReservation": {
            "capacityReservationGroup": {
                "id":null
            }
        }
    }
    }
    

Update the reserved quantity to zero

The second option involves updating the reserved quantity to zero and then changing the capacity reservation group property.

This option works well when the VM can't be deallocated and when a reservation is no longer needed. For example, you might create a capacity reservation to temporarily assure capacity during a large-scale deployment. After it's finished, the reservation is no longer needed.

  1. Update the reserved quantity to zero:

    PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/CapacityReservationGroups/{CapacityReservationGroupName}/CapacityReservations/{CapacityReservationName}?api-version=2021-04-01
    

    In the request body, include the following parameters:

    {
    "sku":
        {
        "capacity": 0
        }
    }
    

    Note that the capacity property is set to 0.

  2. Update the VM to remove the association with the capacity reservation group.

    PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{VirtualMachineName}/update?api-version=2021-04-01
    

    In the request body, set the capacityReservationGroup property to null to remove the association:

    {
    "location": "eastus",
    "properties": {
        "capacityReservation": {
            "capacityReservationGroup": {
                "id":null
            }
        }
    }
    } 
    

Next step