Loading...

Azure Capacity Reservations with Automatic Consumption

Azure Capacity Reservations with Automatic Consumption

Solving the ask – Automatic Capacity Reservations

Historically, the setting to use a Capacity Reservations Groups must be defined while the virtual machine is being deployed or changed while the machine is deallocated. While this is still the requirement, the drafted Azure Policy (at the bottom of this document) automates the additional setting to be specified even if it wasn’t specified on the VM Creation process.

 

For example, some solutions, such as Citrix DaaS hosted on Azure, use automation such as recreation of VMs to handle update management or scalability demands. The update process doesn’t have the ability to add this setting without code changes to their process which requires a significant investment of time per cloud provider to update. If this capacity isn’t available for any reason, the scale out or recreation could fail causing the environment to become unhealthy.

 

What are Azure Capacity Reservations?

Azure Capacity Reservations are a new feature that allows you to reserve compute resources for your virtual machines (VMs) in a specific region and/or availability zone. By using Azure Capacity Reservations, you can ensure that your VMs have guaranteed access to the resources they need, even during periods of high demand or unexpected events.

 

Reserved Virtual Machine Instance (RI) to on-demand Capacity Reservation work together. You can apply existing or future RIs to on-demand capacity reservations and receive RI discounts. Available RIs are applied automatically to Capacity Reservation the same way they're applied to VMs.

 

Azure Capacity Reservation Group (CRG) is a grouping of Capacity Reservations. VM creation targets the CRG and not the specific Capacity Reservation.

 

How to create Azure Capacity Reservations?

To get started with Azure Capacity Reservations, you need to follow these steps:

  • Create a capacity reservation group: A reservation group is a logical container that holds one or more reservations. You can assign VMs to a reservation group to use the reserved resources.
  • Create a capacity reservation: A reservation is a specific amount of compute resources that you reserve for a certain VM size, region, and availability zone. You can create multiple reservations within a reservation group.

 

How do I use the Capacity Reservations?

To deploy your virtual machines to the capacity that is created, you need to follow either of these options:

  • Assign VMs to a reservation group: You can assign existing deallocated VMs or new VMs to a reservation group, either individually or as part of a scale set. The VMs will use the reserved resources from the reservation group, as long as they match the reservation criteria.
  • Leverage Azure Policy (New as of July 2024):
    • Using Azure policy, you can deploy a policy per subscription that specifying:
      • VM SKU
      • Region
      • Target Capacity Reservation
      • Is this a zonal deployment
    • When VMs are created, this policy will automatically add the virtual machine to the Azure Capacity Reservation Group.

 

How do I use Azure Policy to set the Capacity Reservation?

With the below parameters set via policy per subscription, VMs of the desired SKU and availability will automatically be added based on:

  • Region
  • SKU
    • Multiple SKUs can be targeted with the policy
  • Zonal – yes or no
  • Capacity Reservation ID
    • The Capacity reservation targeted with the policy will need to match the zonal decision or VM Creations will fail.

 

Using this functionality, it is now possible to specify a minimum quantity of VM Compute that is guaranteed to be available.

 

 

What does this look like in production?

  1. Create Capacity Reservation Group with correct quantities
  2. Create the policy definition
  3. Assign the policy to have VMs automatically added
  4. Create Virtual Machines

 

Create Capacity Reservations with correct quantities

Create the Capacity Reservation Group to hold the specific Capacity Reservations based on regional or zonal alignment. For each SKU, create a capacity reservation with the minimum amount of compute you wish to be reserved per region or zone. Capacity Reservations can be overallocated. If you reserve 3 nodes of E2s_v4 in zone 1, but attempt to deploy 10 VMs, you are guaranteed to have the 3 available for your consumption and the remaining 7 are subject to normal availability within the zone.

 

In this example, I have created a Capacity Reservation Groups for regional and another for zonal alignment: 

Regional: CRGRG1-WUS3-r

CraigDuBose_4-1721168491543.png

 

Zonal: CRGRG1-WUS3-z

CraigDuBose_5-1721168491544.png

 

 

Create the policy definition

To simplify the experience, I have created a single Azure Policy that is able to be referenced for both scenarios.

An example copy of the policy can be found at the bottom of this article.

 

Assign the policy to have VMs automatically added

Based on the assignment parameters below:

This example for regional:

allowedLocations

westus3

CapacityReservationID

/subscriptions/########-####-####-####-############/resourceGroups/CRGRG/providers/Microsoft.Compute/capacityReservationGroups/CRGRG1-WUS3-r

listOfCRGSKUs

Standard_E2s_v4

Zonal

False

 

Based on the assignment parameters below (this example for zonal):

allowedLocations

westus3

CapacityReservationID

/subscriptions/########-####-####-####-############/resourceGroups/CRGRG/providers/Microsoft.Compute/capacityReservationGroups/CRGRG1-WUS3-z

listOfCRGSKUs

Standard_E2s_v4

Zonal

True

 

 

Create Virtual Machines within the specified context

  • Based on the above, if a VM is created with the SKU E2s_v4 in availability zone 1, it will automatically be added to CRGRG1-WUS3-z.
  • Based on the above, if I create a VM with the SKU E2s_v4 without specifying an availability zone, it will automatically be added to CRGRG1-WUS3-r.

 

The above Azure Policy and assignments added this line of code in the VM Creation template.

 

  "type": "Microsoft.Compute/virtualMachines",

  "location": "westus3",

  "properties": {

    "capacityReservation": {

      "capacityReservationGroup": {

        "id": "/subscriptions/########-####-####-####-############/resourceGroups/CRGRG/providers/Microsoft.Compute/capacityReservationGroups/CRGRG1-WUS3-z"

      }

    }

 

 

An example copy of the policy can be found below: 

The below policy is a draft and is based on new functionality. It should not be treated as production ready unless deemed so by the appropriate resources at your organization. 

 

{

    "mode": "All",

    "policyRule": {

      "if": {

        "allOf": [

          {

            "field": "type",

            "equals": "Microsoft.Compute/virtualMachines"

          },

          {

            "field": "location",

            "in": "[parameters('allowedLocations')]"

          },

          {

            "field": "Microsoft.Compute/virtualMachines/sku.name",

            "in": "[parameters('listOfCRGSKUs')]"

          },

          {

            "field": "Microsoft.Compute/virtualMachines/zones",

            "exists": "[parameters('Zonal')]"

          },

          {

            "field": "Microsoft.Compute/virtualMachines/capacityReservation.capacityReservationGroup.id",

            "notequals": "[parameters('CapacityReservationID')]"

          }

        ]

      },

      "then": {

        "effect": "modify",

        "details": {

          "roleDefinitionIds": [

            "/providers/Microsoft.Authorization/roleDefinitions/9980e02c-c2be-4d73-94e8-173b1dc7cf3c"

          ],

          "operations": [

            {

              "operation": "addOrReplace",

              "field": "Microsoft.Compute/virtualMachines/capacityReservation.capacityReservationGroup.id",

              "value": "[parameters('CapacityReservationID')]"

            }

          ]

        }

      }

    },

    "parameters": {

      "allowedLocations": {

        "type": "Array",

        "metadata": {

          "displayName": "Specific Region that is covered under this CRG",

          "description": "The list of locations that resource groups can be created in.",

          "strongType": "location"

        }

      },

      "listOfCRGSKUs": {

        "type": "Array",

        "metadata": {

          "displayName": "Allowed Size SKUs",

          "description": "The list of size SKUs that can be specified for virtual machines.",

          "strongType": "VMSKUs"

        }

      },

      "CapacityReservationID": {

        "type": "String",

        "metadata": {

          "displayName": "Capacity Reservation ID",

          "description": "The capacity reservation targets this policy to target. Resource ID should be formatted as: '/subscriptions/{SubID}/resourceGroups/{RGName}/providers/Microsoft.Compute/capacityReservationGroups/{CRG Name}.'"

        }

      },

      "Zonal": {

        "type": "String",

        "metadata": {

          "displayName": "Is this Zonal?",

          "description": "If this is Zonal, it will attempt to add to the Zonal Capacity Reservation Groups. If not, it will add to the reginoal Capacity Reservation Groups."

        },

        "allowedValues": [

          "true",

          "false"

        ]

      }

    }

  }

 

 

Published on:

Learn more
Azure Compute Blog articles
Azure Compute Blog articles

Azure Compute Blog articles

Share post:

Related posts

Azure Security: Private Vs. Service Endpoints

When connecting securely to a platform service such as a key vault or an Azure storage account, Microsoft recommends using a private endpoint ...

4 hours ago

Give your Foundry Agent Custom Tools with MCP Servers on Azure Functions

Learn how to connect your MCP server hosted on Azure Functions to Microsoft Foundry agents. This post covers authentication options and setup ...

1 day ago

Azure Data Factory Tips for Reliable Microsoft Dynamics 365 CE and Dataverse Integrations

Reliable integrations between Microsoft Dynamics 365 Customer Engagement and external systems can become challenging. This is especially true ...

1 day ago

Scalable AI with Azure Cosmos DB: Tredence Intelligent Document Processing (IDP) | March 2026

Azure Cosmos DB enables scalable AI-driven document processing, addressing one of the biggest barriers to operational scale in today’s enterpr...

2 days ago

Announcing the end of support for Node.js 20.x in the Azure SDK for JavaScript

After July 9, 2026, the Azure SDK for JavaScript will no longer support Node.js 20.x. Upgrade to an Active Node.js Long Term Support (LTS) ver...

3 days ago

MCP Apps on Azure Functions: Quickstart with TypeScript

Learn how to build and deploy MCP (Model Context Protocol) apps on Azure Functions using TypeScript. This guide covers MCP tools, resources, l...

3 days ago

Setting up Power BI Version Control with Azure Dev Ops

In this blog post is a way set up version control for Power BI semantic models (and reports) using the PBIP (Power BI Project) format, Azure D...

9 days ago

Azure Developer CLI (azd) – March 2026: Run and Debug AI Agents Locally, GitHub Copilot Integration, & Container App Jobs

Run, invoke, and monitor AI agents locally or in Microsoft Foundry with the new azd AI agent extension commands. Plus GitHub Copilot-powered p...

10 days ago

Writing Azure service-related unit tests with Docker using Spring Cloud Azure

This post shows how to write Azure service-related unit tests with Docker using Spring Cloud Azure. The post Writing Azure service-related uni...

10 days ago
Stay up to date with latest Microsoft Dynamics 365 and Power Platform news!
* Yes, I agree to the privacy policy