Remove a VM association from a Capacity Reservation Group (preview)

This article walks you through the steps of removing a VM association to a Capacity Reservation Group. To learn more about capacity reservations, see the overview article.

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:

  • Option 1: Deallocate the Virtual Machine, change the Capacity Reservation Group property, and optionally restart the virtual machine
  • Option 2: Update the reserved quantity to zero and then change the Capacity Reservation Group property

Important

Capacity Reservation is currently in public preview. This preview version is provided without a service-level agreement, and we don't recommend it for production workloads. Certain features might not be supported or might have constrained capabilities. For more information, see Supplemental Terms of Use for Microsoft Azure Previews.

Deallocate the VM

The first option is to deallocate the Virtual Machine, change the Capacity Reservation Group property, and optionally restart the VM.

  1. Deallocate the VM

    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 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 virtual machine can’t be deallocated and when a reservation is no longer needed. For example, you may create a capacity reservation to temporarily assure capacity during a large-scale deployment. Once completed, 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:

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

    Note that capacity property is set to 0 above.

  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 steps