1
---
2
name: compute-on-demand-reservations
3
metadata:
4
version: "1.0.1"
5
category: Compute
6
description: >-
7
Inspects, verifies, and manages Google Compute Engine (GCE) On-Demand reservations
8
and analyzes consumed versus available reserved capacity. Use when checking active
9
reservation capacity, determining whether reserved VMs are available or exhausted,
10
verifying reservation targeting (automatic versus specific reservation), or sharing
11
reservations across projects. Don't use for Spot capacity advice (use
12
gcloud compute advice capacity --provisioning-model=SPOT) or future calendar bookings (use compute-future-reservations).
13
---
14
15
# Compute Engine On-Demand Reservations
16
17
The `compute-on-demand-reservations` skill inspects and manages active Google Compute Engine (GCE) On-Demand reservations. It determines whether guaranteed capacity is available, calculates consumption, verifies instance targeting policies, and audits cross-project sharing.
18
19
## Usage Attribution
20
21
**MUST READ**: Before executing any `gcloud`, REST API, or MCP command, you MUST read and follow the instructions in [Usage Attribution](references/attribution.md).
22
23
---
24
25
## Prerequisites, IAM & Billing
26
27
Before querying or managing On-Demand reservations, ensure the environment meets these requirements:
28
29
1. **Project & Region Configuration**: Prefer passing `--project={project_id}` and `--zone={zone}` directly on each command to avoid overwriting global workstation state, or obtain explicit user confirmation before setting defaults (e.g., `us-central1` / `us-central1-a`):
30
```bash
31
gcloud config set project {project_id}
32
gcloud config set compute/region {region}
33
gcloud config set compute/zone {zone}
34
```
35
2. **Billing & API Enablement**: Ensure the project has an active billing account attached and the Compute Engine API is enabled:
36
```bash
37
gcloud services enable compute.googleapis.com --project={project_id}
38
```
39
3. **Cloud SDK & Authentication**: Ensure the [Google Cloud CLI](https://docs.cloud.google.com/sdk/docs/install-sdk.md.txt) is installed (never execute unprompted host installation commands such as `apt-get` or `curl | bash` without explicit user approval; direct the user to the installation guide instead), then authenticate via `gcloud auth login` (for interactive CLI), `gcloud auth application-default login` (for SDKs), or `GOOGLE_APPLICATION_CREDENTIALS` (for service accounts).
40
4. **IAM Permissions**:
41
* **Read-Only Inspection (`list`, `describe`)**: Grant `roles/compute.viewer` (or custom role with `compute.reservations.list` and `compute.reservations.get`).
42
* **Reservation Lifecycle (`create`, `update`, `delete`)**: Grant `roles/compute.admin` (or custom role with `compute.reservations.create`, `compute.reservations.resize`, `compute.reservations.update`, and `compute.reservations.delete`).
43
* **Consuming Reservations (`instances create`)**: Grant `roles/compute.instanceAdmin.v1` on the project launching VMs (and on **both** the host/owner project and the consumer project when consuming a shared reservation).
44
5. **Quota & Organization Policy**: Creating an On-Demand reservation immediately consumes regional CPU, GPU, or Local SSD quota. For **shared reservations**, Compute Engine deducts regional quota in **both** the host project (at reservation creation) and the consumer project (when VMs launch), and requires the host project to be allowlisted in organization policy `constraints/compute.sharedReservationsOwnerProjects`.
45
6. **Billing & Pricing Warning**: On-Demand reservations are billed immediately upon creation at the full On-Demand VM rate whether or not VMs are running and consuming the reservation. Review [Compute Engine Pricing](https://cloud.google.com/compute/pricing), [Available Regions and Zones](https://docs.cloud.google.com/compute/docs/regions-zones.md.txt), and [Google Cloud Locations](https://cloud.google.com/about/locations) (strip `.md.txt` suffixes when presenting documentation URLs to human users) before provisioning.
46
47
---
48
49
## Command Syntax & Reference
50
51
### 1. List Reservations in a Project / Zone
52
53
```bash
54
gcloud compute reservations list \
55
--project={project_id} \
56
[--filter="zone:({zone})"] \
57
[--format="table(name,zone.basename(),specificReservation.instanceProperties.machineType.basename(),specificReservation.assuredCount,specificReservation.inUseCount,specificReservation.count,specificReservationRequired,shareSettings.shareType,status)"]
58
```
59
60
### 2. Inspect Reservation Details & Capacity Metrics
61
62
```bash
63
gcloud compute reservations describe {reservation_name} \
64
--zone={zone} \
65
--project={project_id}
66
```
67
68
*(Note: Dense accelerator reservations backed by `aggregateReservation` leave `specificReservation.*` columns blank in `list` and expose `aggregateReservation.totalResources` and `aggregateReservation.inUseResources` via `describe`.)*
69
70
### 3. Create a New On-Demand Reservation
71
72
> [!IMPORTANT]
73
> Creating a reservation immediately incurs billing charges. Always obtain explicit human approval before executing `gcloud compute reservations create`.
74
75
```bash
76
gcloud compute reservations create {reservation_name} \
77
--project={project_id} \
78
--zone={zone} \
79
--vm-count={vm_count} \
80
(--machine-type={machine_type} | --source-instance-template={template_name}) \
81
[--min-cpu-platform={min_cpu_platform}] \
82
[--accelerator=count={gpu_count},type={gpu_type}] \
83
[--local-ssd=interface={nvme|scsi}] \
84
[--require-specific-reservation] \
85
[--share-setting=projects --share-with={consumer_project_ids}] # up to 100 consumer projects in the same org (excluding the host project)
86
```
87
88
### 4. Update or Resize an Existing Reservation
89
90
Resizing capacity (`--vm-count`) and modifying shared consumer projects are
91
mutable in place after obtaining explicit human approval (`--share-with`,
92
`--add-share-with`, and `--remove-share-with` accept up to 100 consumer project
93
IDs or project numbers in the same organization excluding the host project
94
itself). Hardware attributes (`machineType`, `minCpuPlatform`, `accelerator`,
95
`localSsd`, `zone`, and `specificReservationRequired`) are immutable after
96
creation and require recreating the reservation.
97
98
```bash
99
gcloud compute reservations update {reservation_name} \
100
--project={project_id} \
101
--zone={zone} \
102
[--vm-count={new_vm_count}] \
103
[--add-share-with={project_ids_or_numbers} | --remove-share-with={project_ids_or_numbers}]
104
```
105
106
### 5. Delete an Unused On-Demand Reservation (Resource Teardown)
107
108
To stop ongoing billing for an unused On-Demand reservation, delete it after obtaining explicit human approval (note: deletion fails if the reservation is attached to a resource-based Committed Use Discount where `commitment` is set—which must be swapped via `gcloud beta compute commitments update-reservations`—or if a targeted reservation with `specificReservationRequired: true` still has `inUseCount > 0`; the command also prompts interactively unless `--quiet` is passed):
109
110
```bash
111
gcloud compute reservations delete {reservation_name} \
112
--zone={zone} \
113
--project={project_id}
114
```
115
116
---
117
118
## Capacity Utilization Analysis
119
120
When inspecting reservation output, verify that the reservation `status` is `READY` or `UPDATING` (exclude reservations in `CREATING` or `DELETING` states) and calculate available capacity using the following fields:
121
122
* **`status`**: Must be `READY` or `UPDATING` before instances can consume reserved capacity. While a reservation is `UPDATING` (for example, during a capacity resize or share-setting modification), its already provisioned capacity remains consumable up to `specificReservation.assuredCount`. Only `CREATING` and `DELETING` states block consumption.
123
* **`specificReservation.assuredCount`**: The number of reserved VM instances currently provisioned and physically backed by Compute Engine hardware. Note that `assuredCount` can be less than `specificReservation.count` while a reservation is actively upsizing or if a physical host failure degrades the reservation (`healthInfo.healthStatus: DEGRADED`).
124
* **`specificReservation.count`**: The total requested target number of VM instances in this reservation block.
125
* **`specificReservation.inUseCount`**: The number of reserved instances currently consumed by running VMs.
126
* **Available Reserved Capacity**:
127
```text
128
Available Capacity = specificReservation.assuredCount - specificReservation.inUseCount
129
```
130
131
### Health & Consumption Thresholds
132
133
* **Available (`> 0`)**: Provisioned reserved capacity is immediately available. Workloads can launch with 100% provisioning assurance.
134
* **Exhausted (`inUseCount >= assuredCount`)**: Provisioned reserved capacity is fully consumed. New instances matching this specification fall back to unreserved on-demand capacity (if allowed) or fail to launch.
135
136
---
137
138
## Reservation Targeting Policies
139
140
Reservations operate under two distinct consumption modes defined by `specificReservationRequired`:
141
142
| Setting | Consumption Mode | Matching Behavior |
143
| :--- | :--- | :--- |
144
| `specificReservationRequired: false` | **Automatic (`ANY_RESERVATION`)** | Any newly created `STANDARD` VM whose properties **identically match all reserved `instanceProperties`** automatically consumes this reservation. |
145
| `specificReservationRequired: true` | **Targeted (`SPECIFIC_RESERVATION`)** | VMs do not consume this capacity unless they match all reserved `instanceProperties` and explicitly specify `--reservation-affinity=specific --reservation={reservation_name}`. |
146
147
### Exact Hardware & Property Matching Requirement
148
149
For a VM to consume a reservation (under either `ANY_RESERVATION` or `SPECIFIC_RESERVATION`), **every** property below must match the reservation's `specificReservation.instanceProperties` 100% identically:
150
151
* **Project and `zone`**: Same project for `LOCAL` reservations, or an authorized consumer project listed in `shareSettings.projectMap`, in the exact same `zone`.
152
* **`machineType`**: Exact machine type shape.
153
* **`minCpuPlatform`**: Must match verbatim. If the reservation was created without an explicit CPU platform (`"Automatic"`), passing `--min-cpu-platform` on the VM does **not** match (and vice versa).
154
* **`guestAccelerators`**: Exact GPU `acceleratorType` and `acceleratorCount` (if any).
155
* **`localSsds`**: Exact Local SSD partition count **and** exact storage interface (`NVME` versus `SCSI`, if any).
156
* **Placement policies**: Exact compact placement `resourcePolicies` and `locationHint` (if present on the reservation).
157
* **`provisioningModel`**: Must be `STANDARD` (`SPOT` VMs never consume On-Demand reservations).
158
159
> [!WARNING]
160
> **Silent Double-Billing Trap**: Under `ANY_RESERVATION` (`--reservation-affinity=any`, the default), if a newly created VM matches `zone` and `machineType` but differs on even a single property (such as `NVME` vs. `SCSI` Local SSD interface or `minCpuPlatform`), Compute Engine silently skips the reservation, launches an unreserved On-Demand VM, and bills for both the idle reservation and the new VM. Creating both the reservation and VMs from the same `--source-instance-template` prevents property drift.
161
162
### VM Provisioning Best Practices
163
164
When provisioning VMs, recommend private networking (`--no-address` paired with IAP TCP forwarding) and a custom least-privilege service account (`--service-account`):
165
166
* To consume a targeted reservation (`specificReservationRequired: true`) during instance creation (note: passing `--reservation-affinity=specific` against a reservation with `specificReservationRequired: false` is rejected by Compute Engine):
167
```bash
168
gcloud compute instances create {vm_name} \
169
--project={project_id} \
170
--zone={zone} \
171
--machine-type={machine_type} \
172
--reservation-affinity=specific \
173
--reservation={reservation_name} \
174
[--no-address] \
175
[--service-account={service_account_email}]
176
```
177
* To prevent an instance from consuming any reservation:
178
```bash
179
gcloud compute instances create {vm_name} \
180
--project={project_id} \
181
--zone={zone} \
182
--machine-type={machine_type} \
183
--reservation-affinity=none \
184
[--no-address] \
185
[--service-account={service_account_email}]
186
```
187
188
---
189
190
## Cross-Project Shared Reservations
191
192
Shared reservations allow multiple projects within the same Google Cloud organization to draw from a shared pool of reserved capacity.
193
194
* Inspect `shareSettings`:
195
* `shareType: LOCAL`: Reservation is private to the host project.
196
* `shareType: SPECIFIC_PROJECTS`: Shared with specific consumer projects keyed under `projectMap` (mapping each project ID or number to `{"projectId": "..."}`).
197
* **Visibility & CUD Caveats**:
198
* Running `gcloud compute reservations list --project={consumer_project_id}` in a consumer project **never** displays shared reservations owned by a host project; always query `--project={host_project_id}` (or Cloud Asset Inventory) to inspect `assuredCount` and `inUseCount`.
199
* Committed Use Discount (CUD) pricing only covers shared reservation consumers when the host and consumer projects belong to the **same Cloud Billing account**.
200
* Consumer projects consume shared capacity by specifying `--project={consumer_project_id}` and referencing the host project in `--reservation`:
201
```bash
202
gcloud compute instances create {vm_name} \
203
--project={consumer_project_id} \
204
--zone={zone} \
205
--machine-type={machine_type} \
206
--reservation-affinity=specific \
207
--reservation=projects/{host_project_id}/reservations/{reservation_name} \
208
[--no-address] \
209
[--service-account={service_account_email}]
210
```
211
212
---
213
214
## Operational Guardrails & Recommendations
215
216
* **Human-Approval Guardrail**: Never execute mutating commands (`gcloud compute reservations create`, `gcloud compute reservations update`, `gcloud compute reservations delete`, or `gcloud compute instances create`) without explicit human approval from the user. Provide copy-pasteable commands and highlight billing implications first.
217
* **Compute Engine MCP Server Guardrail**: When the Compute Engine MCP server is enabled, inspect the in-session MCP tool schemas before invoking them (in case newer MCP server versions add support); unless verified in the current schema:
218
* MCP `list_reservations` is single-zone only and **strips `specific_reservation` counts/shape and `share_settings`** (call `get_reservation_details` per reservation or use `gcloud compute reservations list`).
219
* No MCP tools exist to create, update, or delete reservations.
220
* MCP `create_instance` omits `reservation_affinity`, `min_cpu_platform`, and `local_ssd` (cannot target `SPECIFIC_RESERVATION` or shared reservations and risks silent unreserved double-billing); fall back to `gcloud` CLI when these parameters are absent from the tool schema.
221
* **Missing Reservation Advisory**: When no matching or available reservation exists in the target zone:
222
* Inform the user that instances launch against unreserved on-demand capacity (subject to stock availability).
223
* If guaranteed capacity is required, advise creating a new reservation using `gcloud compute reservations create`.
224
* If the workload is interruptible or fault-tolerant, suggest evaluating Spot
225
VMs using `gcloud compute advice capacity --provisioning-model=SPOT`.
226
* **Negative Guardrail (No Spot Telemetry for On-Demand)**: Do not use Spot
227
capacity advice (`gcloud compute advice capacity --provisioning-model=SPOT`)
228
or emit obtainability scores when inspecting or verifying standard On-Demand
229
reservations. On-Demand reservation checks must inspect concrete reservation
230
status and counts via `gcloud compute reservations list` and `describe`.
231