Remove a VM association from a capacity reservation group
Article
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.
PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{virtualMachineName}/deallocate?api-version=2021-04-01
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:
You know your VM is deallocated when the status changes to Stopped (deallocated).
At this point in the process, the VM is still associated to the capacity reservation group. This association is reflected in the virtualMachinesAssociated property of the capacity reservation.
Select Configuration.
Set the Capacity Reservation group value to None. The VM is no longer associated to the capacity reservation group.
Deallocate the virtual machine:
az vm deallocate
-g myResourceGroup
-n myVM
After the status changes to Stopped (deallocated), the VM is deallocated.
Update the VM to remove association with the capacity reservation group by setting the capacity-reservation-group property to None:
az vm update
-g myresourcegroup
-n myVM
--capacity-reservation-group None
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.
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.
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: