The operation to create or update a capacity reservation group. When updating a capacity reservation group, only tags and sharing profile may be modified. Please refer to https://aka.ms/CapacityReservation for more details.
PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/capacityReservationGroups/{capacityReservationGroupName}?api-version=2026-03-01
URI Parameters
| Name |
In |
Required |
Type |
Description |
|
capacityReservationGroupName
|
path |
True
|
string
|
The name of the capacity reservation group.
|
|
resourceGroupName
|
path |
True
|
string
minLength: 1 maxLength: 90
|
The name of the resource group. The name is case insensitive.
|
|
subscriptionId
|
path |
True
|
string
minLength: 1
|
The ID of the target subscription.
|
|
api-version
|
query |
True
|
string
minLength: 1
|
The API version to use for this operation.
|
Request Body
| Name |
Required |
Type |
Description |
|
location
|
True
|
string
|
The geo-location where the resource lives
|
|
properties.reservationType
|
|
ReservationType
|
Indicates the type of capacity reservation. Allowed values are 'Block' for block capacity reservations and 'Targeted' for reservations that enable a VM to consume a specific capacity reservation when a capacity reservation group is provided. The reservation type is immutable and cannot be changed after it is assigned.
|
|
properties.sharingProfile
|
|
ResourceSharingProfile
|
Specifies the settings to enable sharing across subscriptions for the capacity reservation group resource. The capacity reservation group resource can generally be shared across subscriptions belonging to a single Azure AAD tenant or across AAD tenants if there is a trust relationship established between the tenants. Block capacity reservation does not support sharing across subscriptions. Note: Minimum api-version: 2023-09-01. Please refer to https://aka.ms/computereservationsharing for more details.
|
|
tags
|
|
object
|
Resource tags.
|
|
zones
|
|
string[]
|
The availability zones.
|
Responses
Security
azure_auth
Azure Active Directory OAuth2 Flow.
Type:
oauth2
Flow:
implicit
Authorization URL:
https://login.microsoftonline.com/common/oauth2/authorize
Scopes
| Name |
Description |
|
user_impersonation
|
impersonate your user account
|
Examples
Create or update a block capacity reservation group.
Sample request
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/capacityReservationGroups/blockCapacityReservationGroup?api-version=2026-03-01
{
"location": "westus",
"tags": {
"department": "finance"
},
"zones": [
"1",
"2"
],
"properties": {
"reservationType": "Block"
}
}
import com.azure.resourcemanager.compute.fluent.models.CapacityReservationGroupInner;
import com.azure.resourcemanager.compute.models.ReservationType;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for CapacityReservationGroups CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file: 2026-03-01/capacityReservationExamples/BlockCapacityReservationGroup_CreateOrUpdate.json
*/
/**
* Sample code: Create or update a block capacity reservation group.
*
* @param manager Entry point to ComputeManager.
*/
public static void
createOrUpdateABlockCapacityReservationGroup(com.azure.resourcemanager.compute.ComputeManager manager) {
manager.serviceClient().getCapacityReservationGroups().createOrUpdateWithResponse("myResourceGroup",
"blockCapacityReservationGroup",
new CapacityReservationGroupInner().withLocation("westus").withTags(mapOf("department", "finance"))
.withZones(Arrays.asList("1", "2")).withReservationType(ReservationType.BLOCK),
com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python block_capacity_reservation_group_create_or_update.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.capacity_reservation_groups.create_or_update(
resource_group_name="myResourceGroup",
capacity_reservation_group_name="blockCapacityReservationGroup",
parameters={
"location": "westus",
"properties": {"reservationType": "Block"},
"tags": {"department": "finance"},
"zones": ["1", "2"],
},
)
print(response)
# x-ms-original-file: 2026-03-01/capacityReservationExamples/BlockCapacityReservationGroup_CreateOrUpdate.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v8"
)
// Generated from example definition: 2026-03-01/capacityReservationExamples/BlockCapacityReservationGroup_CreateOrUpdate.json
func ExampleCapacityReservationGroupsClient_CreateOrUpdate_createOrUpdateABlockCapacityReservationGroup() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("{subscription-id}", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
res, err := clientFactory.NewCapacityReservationGroupsClient().CreateOrUpdate(ctx, "myResourceGroup", "blockCapacityReservationGroup", armcompute.CapacityReservationGroup{
Location: to.Ptr("westus"),
Tags: map[string]*string{
"department": to.Ptr("finance"),
},
Zones: []*string{
to.Ptr("1"),
to.Ptr("2"),
},
Properties: &armcompute.CapacityReservationGroupProperties{
ReservationType: to.Ptr(armcompute.ReservationTypeBlock),
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcompute.CapacityReservationGroupsClientCreateOrUpdateResponse{
// CapacityReservationGroup: armcompute.CapacityReservationGroup{
// Location: to.Ptr("westus"),
// Tags: map[string]*string{
// "department": to.Ptr("finance"),
// "owner": to.Ptr("myCompany"),
// },
// Name: to.Ptr("blockCapacityReservationGroup"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/CapacityReservationGroups/blockCapacityReservationGroup"),
// Zones: []*string{
// to.Ptr("1"),
// to.Ptr("2"),
// },
// Properties: &armcompute.CapacityReservationGroupProperties{
// ReservationType: to.Ptr(armcompute.ReservationTypeBlock),
// },
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require("@azure/arm-compute");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to the operation to create or update a capacity reservation group. When updating a capacity reservation group, only tags and sharing profile may be modified. Please refer to https://aka.ms/CapacityReservation for more details.
*
* @summary the operation to create or update a capacity reservation group. When updating a capacity reservation group, only tags and sharing profile may be modified. Please refer to https://aka.ms/CapacityReservation for more details.
* x-ms-original-file: 2026-03-01/capacityReservationExamples/BlockCapacityReservationGroup_CreateOrUpdate.json
*/
async function createOrUpdateABlockCapacityReservationGroup() {
const credential = new DefaultAzureCredential();
const subscriptionId = "{subscription-id}";
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.capacityReservationGroups.createOrUpdate(
"myResourceGroup",
"blockCapacityReservationGroup",
{
location: "westus",
tags: { department: "finance" },
zones: ["1", "2"],
reservationType: "Block",
},
);
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Sample response
{
"name": "blockCapacityReservationGroup",
"location": "westus",
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/CapacityReservationGroups/blockCapacityReservationGroup",
"tags": {
"department": "finance"
},
"zones": [
"1",
"2"
],
"properties": {
"reservationType": "Block"
}
}
{
"location": "westus",
"tags": {
"department": "finance",
"owner": "myCompany"
},
"name": "blockCapacityReservationGroup",
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/CapacityReservationGroups/blockCapacityReservationGroup",
"zones": [
"1",
"2"
],
"properties": {
"reservationType": "Block"
}
}
Create or update a capacity reservation group.
Sample request
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/capacityReservationGroups/myCapacityReservationGroup?api-version=2026-03-01
{
"location": "westus",
"tags": {
"department": "finance"
},
"zones": [
"1",
"2"
],
"properties": {
"sharingProfile": {
"subscriptionIds": [
{
"id": "/subscriptions/{subscription-id1}"
},
{
"id": "/subscriptions/{subscription-id2}"
}
]
}
}
}
import com.azure.core.management.SubResource;
import com.azure.resourcemanager.compute.fluent.models.CapacityReservationGroupInner;
import com.azure.resourcemanager.compute.models.ResourceSharingProfile;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for CapacityReservationGroups CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file: 2026-03-01/capacityReservationExamples/CapacityReservationGroup_CreateOrUpdate.json
*/
/**
* Sample code: Create or update a capacity reservation group.
*
* @param manager Entry point to ComputeManager.
*/
public static void
createOrUpdateACapacityReservationGroup(com.azure.resourcemanager.compute.ComputeManager manager) {
manager.serviceClient().getCapacityReservationGroups().createOrUpdateWithResponse("myResourceGroup",
"myCapacityReservationGroup",
new CapacityReservationGroupInner().withLocation("westus").withTags(mapOf("department", "finance"))
.withZones(Arrays.asList("1", "2"))
.withSharingProfile(new ResourceSharingProfile()
.withSubscriptionIds(Arrays.asList(new SubResource().withId("/subscriptions/{subscription-id1}"),
new SubResource().withId("/subscriptions/{subscription-id2}")))),
com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python capacity_reservation_group_create_or_update.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.capacity_reservation_groups.create_or_update(
resource_group_name="myResourceGroup",
capacity_reservation_group_name="myCapacityReservationGroup",
parameters={
"location": "westus",
"properties": {
"sharingProfile": {
"subscriptionIds": [
{"id": "/subscriptions/{subscription-id1}"},
{"id": "/subscriptions/{subscription-id2}"},
]
}
},
"tags": {"department": "finance"},
"zones": ["1", "2"],
},
)
print(response)
# x-ms-original-file: 2026-03-01/capacityReservationExamples/CapacityReservationGroup_CreateOrUpdate.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v8"
)
// Generated from example definition: 2026-03-01/capacityReservationExamples/CapacityReservationGroup_CreateOrUpdate.json
func ExampleCapacityReservationGroupsClient_CreateOrUpdate_createOrUpdateACapacityReservationGroup() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("{subscription-id}", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
res, err := clientFactory.NewCapacityReservationGroupsClient().CreateOrUpdate(ctx, "myResourceGroup", "myCapacityReservationGroup", armcompute.CapacityReservationGroup{
Location: to.Ptr("westus"),
Tags: map[string]*string{
"department": to.Ptr("finance"),
},
Zones: []*string{
to.Ptr("1"),
to.Ptr("2"),
},
Properties: &armcompute.CapacityReservationGroupProperties{
SharingProfile: &armcompute.ResourceSharingProfile{
SubscriptionIDs: []*armcompute.SubResource{
{
ID: to.Ptr("/subscriptions/{subscription-id1}"),
},
{
ID: to.Ptr("/subscriptions/{subscription-id2}"),
},
},
},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcompute.CapacityReservationGroupsClientCreateOrUpdateResponse{
// CapacityReservationGroup: armcompute.CapacityReservationGroup{
// Location: to.Ptr("westus"),
// Tags: map[string]*string{
// "department": to.Ptr("finance"),
// "owner": to.Ptr("myCompany"),
// },
// Name: to.Ptr("myCapacityReservationGroup"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/CapacityReservationGroups/myCapacityReservationGroup"),
// Zones: []*string{
// to.Ptr("1"),
// to.Ptr("2"),
// },
// Properties: &armcompute.CapacityReservationGroupProperties{
// SharingProfile: &armcompute.ResourceSharingProfile{
// SubscriptionIDs: []*armcompute.SubResource{
// {
// ID: to.Ptr("/subscriptions/{subscription-id1}"),
// },
// {
// ID: to.Ptr("/subscriptions/{subscription-id2}"),
// },
// },
// },
// },
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require("@azure/arm-compute");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to the operation to create or update a capacity reservation group. When updating a capacity reservation group, only tags and sharing profile may be modified. Please refer to https://aka.ms/CapacityReservation for more details.
*
* @summary the operation to create or update a capacity reservation group. When updating a capacity reservation group, only tags and sharing profile may be modified. Please refer to https://aka.ms/CapacityReservation for more details.
* x-ms-original-file: 2026-03-01/capacityReservationExamples/CapacityReservationGroup_CreateOrUpdate.json
*/
async function createOrUpdateACapacityReservationGroup() {
const credential = new DefaultAzureCredential();
const subscriptionId = "{subscription-id}";
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.capacityReservationGroups.createOrUpdate(
"myResourceGroup",
"myCapacityReservationGroup",
{
location: "westus",
tags: { department: "finance" },
zones: ["1", "2"],
sharingProfile: {
subscriptionIds: [
{ id: "/subscriptions/{subscription-id1}" },
{ id: "/subscriptions/{subscription-id2}" },
],
},
},
);
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Sample response
{
"location": "westus",
"tags": {
"department": "finance",
"owner": "myCompany"
},
"name": "myCapacityReservationGroup",
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/CapacityReservationGroups/myCapacityReservationGroup",
"zones": [
"1",
"2"
],
"properties": {
"sharingProfile": {
"subscriptionIds": [
{
"id": "/subscriptions/{subscription-id1}"
},
{
"id": "/subscriptions/{subscription-id2}"
}
]
}
}
}
{
"name": "myCapacityReservationGroup",
"location": "westus",
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/CapacityReservationGroups/myCapacityReservationGroup",
"tags": {
"department": "finance"
},
"zones": [
"1",
"2"
],
"properties": {
"sharingProfile": {
"subscriptionIds": [
{
"id": "/subscriptions/{subscription-id1}"
},
{
"id": "/subscriptions/{subscription-id2}"
}
]
}
}
}
Create or update a targeted capacity reservation group.
Sample request
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/capacityReservationGroups/targetedCapacityReservationGroup?api-version=2026-03-01
{
"location": "westus",
"tags": {
"department": "finance"
},
"zones": [
"1",
"2"
],
"properties": {
"sharingProfile": {
"subscriptionIds": [
{
"id": "/subscriptions/{subscription-id1}"
},
{
"id": "/subscriptions/{subscription-id2}"
}
]
},
"reservationType": "Targeted"
}
}
import com.azure.core.management.SubResource;
import com.azure.resourcemanager.compute.fluent.models.CapacityReservationGroupInner;
import com.azure.resourcemanager.compute.models.ReservationType;
import com.azure.resourcemanager.compute.models.ResourceSharingProfile;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for CapacityReservationGroups CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file: 2026-03-01/capacityReservationExamples/TargetedCapacityReservationGroup_CreateOrUpdate.json
*/
/**
* Sample code: Create or update a targeted capacity reservation group.
*
* @param manager Entry point to ComputeManager.
*/
public static void
createOrUpdateATargetedCapacityReservationGroup(com.azure.resourcemanager.compute.ComputeManager manager) {
manager.serviceClient().getCapacityReservationGroups().createOrUpdateWithResponse("myResourceGroup",
"targetedCapacityReservationGroup",
new CapacityReservationGroupInner().withLocation("westus").withTags(mapOf("department", "finance"))
.withZones(Arrays.asList("1", "2"))
.withSharingProfile(new ResourceSharingProfile()
.withSubscriptionIds(Arrays.asList(new SubResource().withId("/subscriptions/{subscription-id1}"),
new SubResource().withId("/subscriptions/{subscription-id2}"))))
.withReservationType(ReservationType.TARGETED),
com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-compute
# USAGE
python targeted_capacity_reservation_group_create_or_update.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id="SUBSCRIPTION_ID",
)
response = client.capacity_reservation_groups.create_or_update(
resource_group_name="myResourceGroup",
capacity_reservation_group_name="targetedCapacityReservationGroup",
parameters={
"location": "westus",
"properties": {
"reservationType": "Targeted",
"sharingProfile": {
"subscriptionIds": [
{"id": "/subscriptions/{subscription-id1}"},
{"id": "/subscriptions/{subscription-id2}"},
]
},
},
"tags": {"department": "finance"},
"zones": ["1", "2"],
},
)
print(response)
# x-ms-original-file: 2026-03-01/capacityReservationExamples/TargetedCapacityReservationGroup_CreateOrUpdate.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v8"
)
// Generated from example definition: 2026-03-01/capacityReservationExamples/TargetedCapacityReservationGroup_CreateOrUpdate.json
func ExampleCapacityReservationGroupsClient_CreateOrUpdate_createOrUpdateATargetedCapacityReservationGroup() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcompute.NewClientFactory("{subscription-id}", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
res, err := clientFactory.NewCapacityReservationGroupsClient().CreateOrUpdate(ctx, "myResourceGroup", "targetedCapacityReservationGroup", armcompute.CapacityReservationGroup{
Location: to.Ptr("westus"),
Tags: map[string]*string{
"department": to.Ptr("finance"),
},
Zones: []*string{
to.Ptr("1"),
to.Ptr("2"),
},
Properties: &armcompute.CapacityReservationGroupProperties{
SharingProfile: &armcompute.ResourceSharingProfile{
SubscriptionIDs: []*armcompute.SubResource{
{
ID: to.Ptr("/subscriptions/{subscription-id1}"),
},
{
ID: to.Ptr("/subscriptions/{subscription-id2}"),
},
},
},
ReservationType: to.Ptr(armcompute.ReservationTypeTargeted),
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res = armcompute.CapacityReservationGroupsClientCreateOrUpdateResponse{
// CapacityReservationGroup: armcompute.CapacityReservationGroup{
// Location: to.Ptr("westus"),
// Tags: map[string]*string{
// "department": to.Ptr("finance"),
// "owner": to.Ptr("myCompany"),
// },
// Name: to.Ptr("targetedCapacityReservationGroup"),
// ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/CapacityReservationGroups/targetedCapacityReservationGroup"),
// Zones: []*string{
// to.Ptr("1"),
// to.Ptr("2"),
// },
// Properties: &armcompute.CapacityReservationGroupProperties{
// SharingProfile: &armcompute.ResourceSharingProfile{
// SubscriptionIDs: []*armcompute.SubResource{
// {
// ID: to.Ptr("/subscriptions/{subscription-id1}"),
// },
// {
// ID: to.Ptr("/subscriptions/{subscription-id2}"),
// },
// },
// },
// ReservationType: to.Ptr(armcompute.ReservationTypeTargeted),
// },
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ComputeManagementClient } = require("@azure/arm-compute");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to the operation to create or update a capacity reservation group. When updating a capacity reservation group, only tags and sharing profile may be modified. Please refer to https://aka.ms/CapacityReservation for more details.
*
* @summary the operation to create or update a capacity reservation group. When updating a capacity reservation group, only tags and sharing profile may be modified. Please refer to https://aka.ms/CapacityReservation for more details.
* x-ms-original-file: 2026-03-01/capacityReservationExamples/TargetedCapacityReservationGroup_CreateOrUpdate.json
*/
async function createOrUpdateATargetedCapacityReservationGroup() {
const credential = new DefaultAzureCredential();
const subscriptionId = "{subscription-id}";
const client = new ComputeManagementClient(credential, subscriptionId);
const result = await client.capacityReservationGroups.createOrUpdate(
"myResourceGroup",
"targetedCapacityReservationGroup",
{
location: "westus",
tags: { department: "finance" },
zones: ["1", "2"],
sharingProfile: {
subscriptionIds: [
{ id: "/subscriptions/{subscription-id1}" },
{ id: "/subscriptions/{subscription-id2}" },
],
},
reservationType: "Targeted",
},
);
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Sample response
{
"name": "targetedCapacityReservationGroup",
"location": "westus",
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/CapacityReservationGroups/targetedCapacityReservationGroup",
"tags": {
"department": "finance"
},
"zones": [
"1",
"2"
],
"properties": {
"sharingProfile": {
"subscriptionIds": [
{
"id": "/subscriptions/{subscription-id1}"
},
{
"id": "/subscriptions/{subscription-id2}"
}
]
},
"reservationType": "Targeted"
}
}
{
"location": "westus",
"tags": {
"department": "finance",
"owner": "myCompany"
},
"name": "targetedCapacityReservationGroup",
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/CapacityReservationGroups/targetedCapacityReservationGroup",
"zones": [
"1",
"2"
],
"properties": {
"sharingProfile": {
"subscriptionIds": [
{
"id": "/subscriptions/{subscription-id1}"
},
{
"id": "/subscriptions/{subscription-id2}"
}
]
},
"reservationType": "Targeted"
}
}
Definitions
| Name |
Description |
|
ApiError
|
Api error.
|
|
ApiErrorBase
|
Api error base.
|
|
CapacityReservationGroup
|
Specifies information about the capacity reservation group that the capacity reservations should be assigned to. Currently, a capacity reservation can only be added to a capacity reservation group at creation time. An existing capacity reservation cannot be added or moved to another capacity reservation group.
|
|
CapacityReservationGroupInstanceView
|
|
|
CapacityReservationInstanceViewWithName
|
The instance view of a capacity reservation that includes the name of the capacity reservation. It is used for the response to the instance view of a capacity reservation group.
|
|
CapacityReservationUtilization
|
Represents the capacity reservation utilization in terms of resources allocated.
|
|
CloudError
|
An error response from the Compute service.
|
|
createdByType
|
The type of identity that created the resource.
|
|
InnerError
|
Inner error details.
|
|
InstanceViewStatus
|
Instance view status.
|
|
ReservationType
|
Indicates the type of capacity reservation. Allowed values are 'Block' for block capacity reservations and 'Targeted' for reservations that enable a VM to consume a specific capacity reservation when a capacity reservation group is provided. The reservation type is immutable and cannot be changed after it is assigned.
|
|
ResourceSharingProfile
|
|
|
StatusLevelTypes
|
The level code.
|
|
SubResource
|
|
|
SubResourceReadOnly
|
|
|
systemData
|
Metadata pertaining to creation and last modification of the resource.
|
ApiError
Object
Api error.
| Name |
Type |
Description |
|
code
|
string
|
The error code.
|
|
details
|
ApiErrorBase[]
|
The Api error details
|
|
innererror
|
InnerError
|
The Api inner error
|
|
message
|
string
|
The error message.
|
|
target
|
string
|
The target of the particular error.
|
ApiErrorBase
Object
Api error base.
| Name |
Type |
Description |
|
code
|
string
|
The error code.
|
|
message
|
string
|
The error message.
|
|
target
|
string
|
The target of the particular error.
|
CapacityReservationGroup
Object
Specifies information about the capacity reservation group that the capacity reservations should be assigned to. Currently, a capacity reservation can only be added to a capacity reservation group at creation time. An existing capacity reservation cannot be added or moved to another capacity reservation group.
| Name |
Type |
Description |
|
id
|
string
|
Fully qualified resource ID for the resource. Ex - /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}
|
|
location
|
string
|
The geo-location where the resource lives
|
|
name
|
string
|
The name of the resource
|
|
properties.capacityReservations
|
SubResourceReadOnly[]
|
A list of all capacity reservation resource ids that belong to capacity reservation group.
|
|
properties.instanceView
|
CapacityReservationGroupInstanceView
|
The capacity reservation group instance view which has the list of instance views for all the capacity reservations that belong to the capacity reservation group.
|
|
properties.reservationType
|
ReservationType
|
Indicates the type of capacity reservation. Allowed values are 'Block' for block capacity reservations and 'Targeted' for reservations that enable a VM to consume a specific capacity reservation when a capacity reservation group is provided. The reservation type is immutable and cannot be changed after it is assigned.
|
|
properties.sharingProfile
|
ResourceSharingProfile
|
Specifies the settings to enable sharing across subscriptions for the capacity reservation group resource. The capacity reservation group resource can generally be shared across subscriptions belonging to a single Azure AAD tenant or across AAD tenants if there is a trust relationship established between the tenants. Block capacity reservation does not support sharing across subscriptions. Note: Minimum api-version: 2023-09-01. Please refer to https://aka.ms/computereservationsharing for more details.
|
|
properties.virtualMachinesAssociated
|
SubResourceReadOnly[]
|
A list of references to all virtual machines associated to the capacity reservation group.
|
|
systemData
|
systemData
|
Azure Resource Manager metadata containing createdBy and modifiedBy information.
|
|
tags
|
object
|
Resource tags.
|
|
type
|
string
|
The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or "Microsoft.Storage/storageAccounts"
|
|
zones
|
string[]
|
The availability zones.
|
CapacityReservationGroupInstanceView
Object
CapacityReservationInstanceViewWithName
Object
The instance view of a capacity reservation that includes the name of the capacity reservation. It is used for the response to the instance view of a capacity reservation group.
CapacityReservationUtilization
Object
Represents the capacity reservation utilization in terms of resources allocated.
| Name |
Type |
Description |
|
currentCapacity
|
integer
(int32)
|
The value provides the current capacity of the VM size which was reserved successfully and for which the customer is getting billed. Minimum api-version: 2022-08-01.
|
|
virtualMachinesAllocated
|
SubResourceReadOnly[]
|
A list of all virtual machines resource ids allocated against the capacity reservation.
|
CloudError
Object
An error response from the Compute service.
| Name |
Type |
Description |
|
error
|
ApiError
|
Api error.
|
createdByType
Enumeration
The type of identity that created the resource.
| Value |
Description |
|
User
|
|
|
Application
|
|
|
ManagedIdentity
|
|
|
Key
|
|
InnerError
Object
Inner error details.
| Name |
Type |
Description |
|
errordetail
|
string
|
The internal error message or exception dump.
|
|
exceptiontype
|
string
|
The exception type.
|
InstanceViewStatus
Object
Instance view status.
| Name |
Type |
Description |
|
code
|
string
|
The status code.
|
|
displayStatus
|
string
|
The short localizable label for the status.
|
|
level
|
StatusLevelTypes
|
The level code.
|
|
message
|
string
|
The detailed status message, including for alerts and error messages.
|
|
time
|
string
(date-time)
|
The time of the status.
|
ReservationType
Enumeration
Indicates the type of capacity reservation. Allowed values are 'Block' for block capacity reservations and 'Targeted' for reservations that enable a VM to consume a specific capacity reservation when a capacity reservation group is provided. The reservation type is immutable and cannot be changed after it is assigned.
| Value |
Description |
|
Targeted
|
To consume on demand allocated capacity reservation when a capacity reservation group is provided.
|
|
Block
|
To consume scheduled allocated block capacity reservation when a capacity reservation group is provided.
|
ResourceSharingProfile
Object
| Name |
Type |
Description |
|
subscriptionIds
|
SubResource[]
|
Specifies an array of subscription resource IDs that capacity reservation group is shared with. Block Capacity Reservations does not support sharing across subscriptions. Note: Minimum api-version: 2023-09-01. Please refer to https://aka.ms/computereservationsharing for more details.
|
StatusLevelTypes
Enumeration
The level code.
| Value |
Description |
|
Info
|
|
|
Warning
|
|
|
Error
|
|
SubResource
Object
| Name |
Type |
Description |
|
id
|
string
|
Resource Id
|
SubResourceReadOnly
Object
| Name |
Type |
Description |
|
id
|
string
|
Resource Id
|
systemData
Object
Metadata pertaining to creation and last modification of the resource.
| Name |
Type |
Description |
|
createdAt
|
string
(date-time)
|
The timestamp of resource creation (UTC).
|
|
createdBy
|
string
|
The identity that created the resource.
|
|
createdByType
|
createdByType
|
The type of identity that created the resource.
|
|
lastModifiedAt
|
string
(date-time)
|
The timestamp of resource last modification (UTC)
|
|
lastModifiedBy
|
string
|
The identity that last modified the resource.
|
|
lastModifiedByType
|
createdByType
|
The type of identity that last modified the resource.
|