Create a shared reservation

This document explains how to create shared reservations, which are reservations shared across multiple projects, and manage which projects in your organization can consume the shared reservations.

A shared reservation can be used by the project that hosts the reservation (owner project) and by the projects the reservation is shared with (consumer projects). Use shared reservations if your organization has multiple projects that need virtual machine (VM) instances with the same properties reserved. By using shared reservations, you can improve the utilization of your reservations and reduce the number of reservations that you need to create and manage. To learn more about reservations, see Reservations of Compute Engine zonal resources.

For other methods of creating reservations, see instead the following pages:

Before you begin

Required roles

To get the permissions that you need to create shared reservations, ask your administrator to grant you the following IAM roles :

For more information about granting roles, see Manage access to projects, folders, and organizations.

These predefined roles contain the permissions required to create shared reservations. To see the exact permissions that are required, expand the Required permissions section:

Required permissions

The following permissions are required to create shared reservations:

  • compute.reservations.create on the project
  • To view organization policies: orgpolicy.policy.get on the organization
  • To edit organization policies: orgpolicy.policy.set on the organization
  • To specify an instance template: compute.instanceTemplates.useReadOnly on the instance template

You might also be able to get these permissions with custom roles or other predefined roles.

This section explains how to create shared reservations. After you create a shared reservation, it can be modified only by the owner project, but the resources for a shared reservation can be consumed by the owner project or any consumer projects.

To consume a reservation, a VM must have properties that exactly match that reservation. To specify the properties of the VMs that you want to reserve, select one of the following sections in this document:

  • Recommended: Specify an instance template

    This section explains how to use an instance template to define the properties of a shared reservation. By using an instance template, you can define the properties of a reservation and the VMs that can consume the reservation in the same place. However, because templates are project-specific, you can't use the same template to create VMs that can consume the reservation outside of the project that created the reservation. For the projects the reservation is shared with, you must create similar templates in those projects or create VMs by specifying properties directly.

  • Specify an existing VM

    This section explains how to use an existing VM to define the properties of a reservation. By using the properties of an existing VM, you can consume the reservation by creating VMs with properties that match the reference VM.

  • Specify properties directly

    This section explains how to directly define the properties of a shared reservation. This method requires you to manually ensure that the properties of your VMs and reservations match exactly—any mismatched properties prevent consumption.

By default, a reservation can be automatically consumed by any VMs with properties that match it. If you want to control reservation consumption, do one or more of the following:

Specify an instance template

Before creating a reservation by specifying an instance template, make sure of the following:

  • An instance template contains project-specific settings, so you can only access and use an instance template within the same project. If you create a shared reservation by specifying an instance template, then you can't use the same template to create VMs that can consume the reservation outside of the project that created the reservation.

  • Create your reservation in the same region and zone as the resources within the instance template. Any regional or zonal resources specified in an instance template—such as a machine type or a Persistent Disk volume—restrict the use of the template to the locations where those resources exist. For example, if your instance template specifies an existing Persistent Disk volume in zone us-central1-a, then you can only create your reservation in the same zone. To check if an existing template specifies any resources that bind the template to a specific region or zone, view the details of the instance template and look for references to regional or zonal resources inside of it.

To create a shared reservation by specifying an instance template, select one of the following options:

Console

  1. In the Google Cloud console, go to the Reservations page.

    Go to Reservations

  2. Click Create reservation. The Create a reservation page appears.

  3. In the Name field, enter a name for your reservation.

  4. In the Region and Zone lists, select where you want to reserve resources.

  5. In the Share type section, do the following:

    1. To share a reservation with other projects, select Shared.

    2. Click Add projects, and then select the projects from the current project's organization that you want to share the reservation with. You can select up to 100 consumer projects.

  6. Optional: To let custom training jobs or prediction jobs in Vertex AI consume a reservation of GPU VMs, in the Google Cloud services section, select Share reservation.

  7. In the Use with VM instance section, select one of the following options:

    • To allow matching VMs to automatically consume this reservation, select Use reservation automatically.

    • To consume this reservation's resources only when you create matching VMs that specifically target the reservation by name, select Select specific reservation.

  8. In the Resource details section, do the following:

    • In the Number of VM instances field, enter the number of VMs that you want to reserve.

    • To specify VM configurations by using an instance template, select Use instance template, and then, in the list that appears, select the instance template.

  9. In the Auto-delete section, you can enable the auto-delete option to let Compute Engine automatically delete the reservation at a specific date and time. Automatically deleting reservations can be useful to avoid unnecessary charges when you stop consuming the reservation.

  10. To create the reservation, click Create. The Reservations page appears. Creating the reservation can take up to a minute to complete. To verify when Compute Engine finishes creating it, view your reservations.

gcloud

To create a shared reservation, use the gcloud compute reservations create command with the --share-setting=projects and --share-with flags.

To create a shared reservation by specifying an instance template and without including any optional flags, run the following command:

gcloud compute reservations create RESERVATION_NAME \
    --share-setting=projects \
    --share-with=CONSUMER_PROJECT_IDS \
    --source-instance-template=INSTANCE_TEMPLATE_URL \
    --vm-count=NUMBER_OF_VMS \
    --zone=ZONE

Replace the following:

  • RESERVATION_NAME: the name of the reservation to create.

  • PROJECT_ID: the ID of the project where you want to reserve resources and where the instance template exists.

  • CONSUMER_PROJECT_IDS: a comma-separated list of IDs of projects that can consume this reservation—for example, project-1,project-2. You can include up to 100 consumer projects. These projects must be in the same organization as the owner project. Don't include the owner project. By default, it's already allowed to consume the reservation.

  • INSTANCE_TEMPLATE_URL: the URL of an existing instance template, which must exist in your project. Specify one of the following values:

    • For a regional instance template: projects/PROJECT_ID/regions/REGION/instanceTemplates/INSTANCE_TEMPLATE_NAME

    • For a global instance template: INSTANCE_TEMPLATE_NAME

  • NUMBER_OF_VMS: the number of VMs to reserve.

  • ZONE: the zone in which to reserve resources.

For example, to create a reservation by specifying a global instance template in zone us-central1-a, share the reservation with projects project-1 and project-2, and reserve ten VMs that each use an N2 predefined machine type with 4 vCPUs, run the following command:

gcloud compute reservations create my-reservation \
    --share-setting=projects \
    --share-with=project-1,project-2 \
    --source-instance-template=projects/example-project/global/example-instance-template \
    --vm-count=10 \
    --zone=us-central1-a

Optionally, you can do one or more of the following:

  • To specify that only VMs that specifically target this reservation can consume it, include the --require-specific-reservation flag.

    gcloud compute reservations create RESERVATION_NAME \
        --require-specific-reservation \
        --share-setting=projects \
        --share-with=CONSUMER_PROJECT_IDS \
        --source-instance-template=INSTANCE_TEMPLATE_URL \
        --vm-count=NUMBER_OF_VMS \
        --zone=ZONE
    
  • To let custom training jobs or prediction jobs in Vertex AI consume a reservation of GPU VMs, include the --reservation-sharing-policy flag set to ALLOW_ALL.

    gcloud compute reservations create RESERVATION_NAME \
        --reservation-sharing-policy=ALLOW_ALL \
        --share-setting=projects \
        --share-with=CONSUMER_PROJECT_IDS \
        --source-instance-template=INSTANCE_TEMPLATE_URL \
        --vm-count=NUMBER_OF_VMS \
        --zone=ZONE
    
  • To enable Compute Engine to automatically delete the reservation, select one of the following methods:

    • To delete the reservation at a specific date and time, use the gcloud beta compute reservations create command with the --delete-at-time flag.

      gcloud beta compute reservations create RESERVATION_NAME \
          --delete-at-time=DELETE_AT_TIME \
          --share-setting=projects \
          --share-with=CONSUMER_PROJECT_IDS \
          --source-instance-template=INSTANCE_TEMPLATE_URL \
          --vm-count=NUMBER_OF_VMS \
          --zone=ZONE
      

      Replace DELETE_AT_TIME with a date and time formatted as an RFC 3339 timestamp, which must be as follows:

      YYYY-MM-DDTHH:MM:SSOFFSET
      

      Replace the following:

      • YYYY-MM-DD: a date formatted as a 4-digit year, 2-digit month, and a 2-digit day of the month, separated by hyphens (-).

      • HH:MM:SS: a time formatted as a 2-digit hour using a 24-hour time, 2-digit minutes, and 2-digit seconds, separated by colons (:).

      • OFFSET: the time zone formatted as an offset of Coordinated Universal Time (UTC). For example, to use the Pacific Standard Time (PST), specify -08:00. Alternatively, to use no offset, specify Z.

    • To delete the reservation after a specific duration, use the gcloud beta compute reservations create command with the --delete-after-duration flag.

      gcloud beta compute reservations create RESERVATION_NAME \
          --delete-after-duration=DELETE_AFTER_DURATION \
          --share-setting=projects \
          --share-with=CONSUMER_PROJECT_IDS \
          --source-instance-template=INSTANCE_TEMPLATE_URL \
          --vm-count=NUMBER_OF_VMS \
          --zone=ZONE
      

      Replace DELETE_AFTER_DURATION with a duration in days, hours, minutes, or seconds. For example, specify 30m for 30 minutes, or 1d2h3m4s for 1 day, 2 hours, 3 minutes, and 4 seconds.

Go

Java

Node.js

Python

REST

To create a shared reservation, make a POST request to the reservations.insert method. In the request body, include the following:

  • The projectMap field.

  • The shareType field set to SPECIFIC_PROJECTS.

For example, to create a shared reservation by specifying an instance template without including any optional fields, and share the reservation with two consumer projects, make the following POST request:

POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/reservations

{
  "name": "RESERVATION_NAME",
  "shareSettings": {
    "shareType": "SPECIFIC_PROJECTS",
    "projectMap": {
      "CONSUMER_PROJECT_ID_1": {
        "projectId": "CONSUMER_PROJECT_ID_1"
      },
      "CONSUMER_PROJECT_ID_2": {
        "projectId": "CONSUMER_PROJECT_ID_2"
      }
    }
  },
  "specificReservation": {
    "count": "NUMBER_OF_VMS",
    "sourceInstanceTemplate": "INSTANCE_TEMPLATE_URL"
  }
}

Replace the following:

  • PROJECT_ID: the ID of the project where you want to reserve resources and where the instance template exists.

  • ZONE: the zone in which to reserve resources.

  • RESERVATION_NAME: the name of the reservation to create.

  • CONSUMER_PROJECT_ID_1 and CONSUMER_PROJECT_ID_2: the IDs of projects that can consume this reservation. You can include up to 100 consumer projects. These projects must be in the same organization as the owner project. Don't include the owner project. By default, it is already allowed to consume the reservation.

  • NUMBER_OF_VMS: the number of VMs to reserve.

  • INSTANCE_TEMPLATE_URL: the URL of an existing instance template, which must exist in your project. Specify one of the following values:

    • For a regional instance template: projects/PROJECT_ID/regions/REGION/instanceTemplates/INSTANCE_TEMPLATE_NAME

    • For a global instance template: INSTANCE_TEMPLATE_NAME

For example, to create a reservation for ten VMs in zone us-central1-a by specifying a global instance template, and share the reservation with projects project-1 and project-2, make the following POST request:

POST https://compute.googleapis.com/compute/v1/projects/example-project/zones/us-central1-a/reservations

{
  "name": "my-reservation",
  "shareSettings": {
    "shareType": "SPECIFIC_PROJECTS",
    "projectMap": {
      "project-1": {
        "projectId": "project-1"
      },
      "project-2": {
        "projectId": "project-2"
      }
    }
  },
  "specificReservation": {
    "count": "10",
    "sourceInstanceTemplate": "example-instance-template"
  }
}

Optionally, you can do one or more of the following:

  • To specify that only VMs that specifically target this reservation can consume it, include the specificReservationRequired field in the request body, and set the field to true.

    For example, to create a specific reservation by specifying an instance template, and share the reservation with two consumer projects, make a request as follows:

    POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/reservations
    
    {
      "name": "RESERVATION_NAME",
      "shareSettings": {
        "shareType": "SPECIFIC_PROJECTS",
        "projectMap": {
          "CONSUMER_PROJECT_ID_1": {
            "projectId": "CONSUMER_PROJECT_ID_1"
          },
          "CONSUMER_PROJECT_ID_2": {
            "projectId": "CONSUMER_PROJECT_ID_2"
          }
        }
      },
      "specificReservation": {
        "count": "NUMBER_OF_VMS",
        "sourceInstanceTemplate": "INSTANCE_TEMPLATE_URL"
      },
      "specificReservationRequired": true
    }
    
  • To let custom training jobs or prediction jobs in Vertex AI consume a reservation of GPU VMs, include the serviceShareType field and set it to ALLOW_ALL.

    POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/reservations
    
    {
      "name": "RESERVATION_NAME",
      "reservationSharingPolicy": {
        "serviceShareType": "ALLOW_ALL"
      },
      "shareSettings": {
        "shareType": "SPECIFIC_PROJECTS",
        "projectMap": {
          "CONSUMER_PROJECT_ID_1": {
            "projectId": "CONSUMER_PROJECT_ID_1"
          },
          "CONSUMER_PROJECT_ID_2": {
            "projectId": "CONSUMER_PROJECT_ID_2"
          }
        }
      },
      "specificReservation": {
        "count": "NUMBER_OF_VMS",
        "sourceInstanceTemplate": "INSTANCE_TEMPLATE_URL"
      }
    }
    
  • To enable Compute Engine to automatically delete the reservation, select one of the following methods:

    • To delete the reservation at a specific date and time, make a POST request to the beta.reservations.insert method. In the request body, include the deleteAtTime field.

      For example, to create a reservation by specifying an instance template, auto delete the reservation at a specific date and time, and share the reservation with two consumer projects, make a request as follows:

      POST https://compute.googleapis.com/compute/beta/projects/PROJECT_ID/zones/ZONE/reservations
      
      {
        "deleteAtTime": "DELETE_AT_TIME",
        "name": "RESERVATION_NAME",
        "shareSettings": {
          "shareType": "SPECIFIC_PROJECTS",
          "projectMap": {
            "CONSUMER_PROJECT_ID_1": {
              "projectId": "CONSUMER_PROJECT_ID_1"
            },
            "CONSUMER_PROJECT_ID_2": {
              "projectId": "CONSUMER_PROJECT_ID_2"
            }
          }
        },
        "specificReservation": {
          "count": "NUMBER_OF_VMS",
          "sourceInstanceTemplate": "INSTANCE_TEMPLATE_URL"
        }
      }
      

      Replace DELETE_AT_TIME with a date and time formatted as an RFC 3339 timestamp, which must be as follows:

      YYYY-MM-DDTHH:MM:SSOFFSET
      

      Replace the following:

      • YYYY-MM-DD: a date formatted as a 4-digit year, 2-digit month, and a 2-digit day of the month, separated by hyphens (-).

      • HH:MM:SS: a time formatted as a 2-digit hour using a 24-hour time, 2-digit minutes, and 2-digit seconds, separated by colons (:).

      • OFFSET: the time zone formatted as an offset of Coordinated Universal Time (UTC). For example, to use the Pacific Standard Time (PST), specify -08:00. Alternatively, to use no offset, specify Z.

    • To delete the reservation after a specific duration, make a POST request to the beta.reservations.insert method. In the request body, include the deleteAfterDuration field.

      For example, to create a reservation by specifying an instance template, auto delete the reservation after a specific duration, and share the reservation with two consumer projects, make a request as follows:

      POST https://compute.googleapis.com/compute/beta/projects/PROJECT_ID/zones/ZONE/reservations
      
      {
        "deleteAfterDuration": {
          "seconds": "DELETE_AFTER_DURATION"
        },
        "name": "RESERVATION_NAME",
        "shareSettings": {
          "shareType": "SPECIFIC_PROJECTS",
          "projectMap": {
            "CONSUMER_PROJECT_ID_1": {
              "projectId": "CONSUMER_PROJECT_ID_1"
            },
            "CONSUMER_PROJECT_ID_2": {
              "projectId": "CONSUMER_PROJECT_ID_2"
            }
          }
        },
        "specificReservation": {
          "count": "NUMBER_OF_VMS",
          "sourceInstanceTemplate": "INSTANCE_TEMPLATE_URL"
        }
      }
      

      Replace DELETE_AFTER_DURATION with a duration in seconds. For example, specify 86400 for 86,400 seconds (1 day).

Specify an existing VM

You can only create a shared reservation based on an existing VM in the same project and zone as the VM.

After creating the reservation, you can consume it by creating VMs with properties that match the reference VM. You can do this by doing one of the following:

To create a shared reservation that uses the properties of an existing VM, do the following:

  1. In the Google Cloud console, go to the Reservations page.

    Go to Reservations

  2. Click Create reservation. The Create a reservation page appears.

  3. In the Name field, enter a name for your reservation.

  4. In the Region and Zone lists, select where you want to reserve resources.

  5. In the Share type section, do the following:

    1. To share a reservation with other projects, select Shared.

    2. Click Add projects, and then select the projects from the current project's organization that you want to share the reservation with. You can select up to 100 consumer projects.

  6. Optional: To let custom training jobs or prediction jobs in Vertex AI consume a reservation of GPU VMs, in the Google Cloud services section, select Share reservation.

  7. In the Use with VM instance section, select one of the following options:

    • To allow matching VMs to automatically consume this reservation, select Use reservation automatically.

    • To consume this reservation's resources only when you create matching VMs that specifically target the reservation by name, select Select specific reservation.

  8. In the Resource details section, do the following:

    • In the Number of VM instances field, enter the number of VMs that you want to reserve.

    • To specify VM configurations by using a reference VM, select Use existing VM, and then, in the list that appears, select the VM.

  9. In the Auto-delete section, you can enable the auto-delete option to let Compute Engine automatically delete the reservation at a specific date and time. Automatically deleting reservations can be useful to avoid unnecessary charges when you stop consuming the reservation.

  10. To create the reservation, click Create. The Reservations page appears. Creating the reservation can take up to a minute to complete. To verify when Compute Engine finishes creating it, view your reservations.

Specify properties directly

To create a shared reservation by specifying properties directly, select one of the following options:

Console

  1. In the Google Cloud console, go to the Reservations page.

    Go to Reservations

  2. Click Create reservation. The Create a reservation page appears.

  3. In the Name field, enter a name for your reservation.

  4. In the Region and Zone lists, select where you want to reserve resources.

  5. In the Share type section, do the following:

    1. To share a reservation with other projects, select Shared.

    2. Click Add projects, and then select the projects from the current project's organization that you want to share the reservation with. You can select up to 100 consumer projects.

  6. Optional: To let custom training jobs or prediction jobs in Vertex AI consume a reservation of GPU VMs, in the Google Cloud services section, select Share reservation.

  7. In the Use with VM instance section, select one of the following options:

    • To allow matching VMs to automatically consume this reservation, select Use reservation automatically.

    • To consume this reservation's resources only when you create matching VMs that specifically target the reservation by name, select Select specific reservation.

  8. In the Resource details section, do the following:

    • In the Number of VM instances field, enter the number of VMs that you want to reserve.

    • Specify the machine series and type that you want to reserve.

  9. In the Auto-delete section, you can enable the auto-delete option to let Compute Engine automatically delete the reservation at a specific date and time. Automatically deleting reservations can be useful to avoid unnecessary charges when you stop consuming the reservation.

  10. To create the reservation, click Create. The Reservations page appears. Creating the reservation can take up to a minute to complete. To verify when Compute Engine finishes creating it, view your reservations.

gcloud

To create a shared reservation, use the gcloud compute reservations create command with the --share-setting=projects and --share-with flags.

To create a shared reservation by specifying properties directly and without including any optional flags, run the following command:

gcloud compute reservations create RESERVATION_NAME \
    --machine-type=MACHINE_TYPE \
    --share-setting=projects \
    --share-with=CONSUMER_PROJECT_IDS \
    --vm-count=NUMBER_OF_VMS \
    --zone=ZONE

Replace the following:

  • RESERVATION_NAME: the name of the reservation to create.

  • MACHINE_TYPE: a machine type to use for each VM.

  • CONSUMER_PROJECT_IDS: a comma-separated list of IDs of projects that can consume this reservation—for example, project-1,project-2. You can include up to 100 consumer projects. These projects must be in the same organization as the owner project. Don't include the owner project. By default, it is already allowed to consume the reservation.

  • NUMBER_OF_VMS: the number of VMs to reserve.

  • ZONE: the zone in which to reserve resources.

For example, to create a reservation in zone us-central1-a for ten VMs that each use an N2 predefined machine type with 4 vCPUs, and share the reservation with projects project-1 and project-2, run the following command:

gcloud compute reservations create my-reservation \
    --machine-type=n2-standard-4 \
    --share-setting=projects \
    --share-with=project-1,project-2 \
    --vm-count=10 \
    --zone=us-central1-a

Optionally, you can do one or more of the following:

  • To attach GPUs to your reserved N1 VMs, include the --accelerator flag.

    gcloud compute reservations create RESERVATION_NAME \
        --accelerator=count=NUMBER_OF_ACCELERATORS,type=ACCELERATOR_TYPE
        --machine-type=MACHINE_TYPE \
        --share-setting=projects \
        --share-with=CONSUMER_PROJECT_IDS \
        --vm-count=NUMBER_OF_VMS \
        --zone=ZONE
    

    Replace the following:

  • To attach Local SSD disks to a machine type that doesn't include Local SSD disks by default, include the --local-ssd flag. You can only attach Local SSD disks of 375 GB.

    gcloud compute reservations create RESERVATION_NAME \
        --local-ssd=count=NUMBER_OF_LOCAL_SSD_DISKS,size=375,interface=INTERFACE_TYPE \
        --machine-type=MACHINE_TYPE \
        --vm-count=NUMBER_OF_VMS \
        --zone=ZONE
    

    Replace the following:

    • NUMBER_OF_LOCAL_SSD_DISKS: the number of Local SSD disks to attach.

    • INTERFACE_TYPE: the type of disk interface that you want each Local SSD disk to use and that your specified machine type supports. Specify one of the following values:

      • For the NVME disk interface: nvme

      • For the SCSI disk interface: scsi

  • To have the reserved VMs use a specific minimum CPU platform instead of the zone's default CPU platform, include the --min-cpu-platform flag.

    gcloud compute reservations create RESERVATION_NAME \
        --machine-type=MACHINE_TYPE \
        --min-cpu-platform="MIN_CPU_PLATFORM" \
        --share-setting=projects \
        --share-with=CONSUMER_PROJECT_IDS \
        --vm-count=NUMBER_OF_VMS \
        --zone=ZONE
    

    Replace MIN_CPU_PLATFORM with a minimum CPU platform. To make sure that a CPU platform is available in the zone where you're reserving resources, view the available CPU platforms by zone.

  • To specify that only VMs that specifically target this reservation can consume it, include the --require-specific-reservation flag.

    gcloud compute reservations create RESERVATION_NAME \
        --machine-type=MACHINE_TYPE \
        --require-specific-reservation \
        --share-setting=projects \
        --share-with=CONSUMER_PROJECT_IDS \
        --vm-count=NUMBER_OF_VMS \
        --zone=ZONE
    
  • To let custom training jobs or prediction jobs in Vertex AI consume a reservation of GPU VMs, include the --reservation-sharing-policy flag set to ALLOW_ALL.

    gcloud compute reservations create RESERVATION_NAME \
        --machine-type=MACHINE_TYPE \
        --reservation-sharing-policy=ALLOW_ALL \
        --share-setting=projects \
        --share-with=CONSUMER_PROJECT_IDS \
        --vm-count=NUMBER_OF_VMS \
        --zone=ZONE
    
  • To enable Compute Engine to automatically delete the reservation, select one of the following methods:

    • To delete the reservation at a specific date and time, use the gcloud beta compute reservations create command with the --delete-at-time flag.

      gcloud beta compute reservations create RESERVATION_NAME \
          --delete-at-time=DELETE_AT_TIME \
          --machine-type=MACHINE_TYPE \
          --share-setting=projects \
          --share-with=CONSUMER_PROJECT_IDS \
          --vm-count=NUMBER_OF_VMS \
          --zone=ZONE
      

      Replace DELETE_AT_TIME with a date and time formatted as an RFC 3339 timestamp, which must be as follows:

      YYYY-MM-DDTHH:MM:SSOFFSET
      

      Replace the following:

      • YYYY-MM-DD: a date formatted as a 4-digit year, 2-digit month, and a 2-digit day of the month, separated by hyphens (-).

      • HH:MM:SS: a time formatted as a 2-digit hour using a 24-hour time, 2-digit minutes, and 2-digit seconds, separated by colons (:).

      • OFFSET: the time zone formatted as an offset of Coordinated Universal Time (UTC). For example, to use the Pacific Standard Time (PST), specify -08:00. Alternatively, to use no offset, specify Z.

    • To delete the reservation after a specific duration, use the gcloud beta compute reservations create command with the --delete-after-duration flag.

      gcloud beta compute reservations create RESERVATION_NAME \
          --delete-after-duration=DELETE_AFTER_DURATION \
          --machine-type=MACHINE_TYPE \
          --share-setting=projects \
          --share-with=CONSUMER_PROJECT_IDS \
          --vm-count=NUMBER_OF_VMS \
          --zone=ZONE
      

      Replace DELETE_AFTER_DURATION with a duration in days, hours, minutes, or seconds. For example, specify 30m for 30 minutes, or 1d2h3m4s for 1 day, 2 hours, 3 minutes, and 4 seconds.

Terraform

To create a reservation, use the google_compute_reservation Terraform resource. To share a reservation with other projects, define the share_settings block:

  • Set the share_type field to SPECIFIC_PROJECTS.
  • In the project_map block, specify the project IDs of the projects that you want to share this reservation with.

For more information about how to use Terraform, see Using Terraform with Google Cloud.

REST

To create a shared reservation, make a POST request to the reservations.insert method. In the request body, include the following:

  • The projectMap field.

  • The shareType field set to SPECIFIC_PROJECTS.

For example, to create a shared reservation without including any optional fields and share the reservation with two consumer projects, make the following POST request:

POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/reservations

{
  "name": "RESERVATION_NAME",
  "shareSettings": {
    "shareType": "SPECIFIC_PROJECTS",
    "projectMap": {
      "CONSUMER_PROJECT_ID_1": {
        "projectId": "CONSUMER_PROJECT_ID_1"
      },
      "CONSUMER_PROJECT_ID_2": {
        "projectId": "CONSUMER_PROJECT_ID_2"
      }
    }
  },
  "specificReservation": {
    "count": "NUMBER_OF_VMS",
    "instanceProperties": {
      "machineType": "MACHINE_TYPE"
    }
  }
}

Replace the following:

  • PROJECT_ID: the ID of the project where you want to reserve resources.

  • ZONE: the zone in which to reserve resources.

  • RESERVATION_NAME: the name of the reservation to create.

  • CONSUMER_PROJECT_ID_1 and CONSUMER_PROJECT_ID_2: the IDs of projects that can consume this reservation. You can include up to 100 consumer projects. These projects must be in the same organization as the owner project. Don't include the owner project. By default, it is already allowed to consume the reservation.

  • NUMBER_OF_VMS: the number of VMs to reserve.

  • MACHINE_TYPE: a machine type to use for each VM.

For example, to create a reservation by specifying a global instance template in zone us-central1-a, share the reservation with projects project-1 and project-2, and reserve ten VMs that each use an N2 predefined machine type with 4 vCPUs, make the following POST request:

POST https://compute.googleapis.com/compute/v1/projects/example-project/zones/us-central1-a/reservations

{
  "name": "my-reservation",
  "shareSettings": {
    "shareType": "SPECIFIC_PROJECTS",
    "projectMap": {
      "project-1": {
        "projectId": "project-1"
      },
      "project-2": {
        "projectId": "project-2"
      }
    }
  },
  "specificReservation": {
    "count": "10",
    "instanceProperties": {
      "machineType": "n2-standard-4",
    }
  }
}

Optionally, you can do one or more of the following:

  • To attach GPUs to your reserved N1 VMs, include the guestAccelerators field in the request body.

    For example, to create a reservation shared with two consumer projects, and attach GPUs to any reserved N1 VMs, make a request as follows:

    POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/reservations
    
    {
      "name": "RESERVATION_NAME",
      "shareSettings": {
        "shareType": "SPECIFIC_PROJECTS",
        "projectMap": {
          "CONSUMER_PROJECT_ID_1": {
            "projectId": "CONSUMER_PROJECT_ID_1"
          },
          "CONSUMER_PROJECT_ID_2": {
            "projectId": "CONSUMER_PROJECT_ID_2"
          }
        }
      },
      "specificReservation": {
        "count": "NUMBER_OF_VMS",
        "instanceProperties": {
          "guestAccelerators": [
            {
              "acceleratorCount": NUMBER_OF_ACCELERATORS,
              "acceleratorType": "ACCELERATOR_TYPE"
            }
          ],
          "machineType": "MACHINE_TYPE"
        }
      }
    }
    

    Replace the following:

  • To attach Local SSD disks to a machine type that doesn't include Local SSD disks by default, include the localSsds field in the request body. You can only attach Local SSD disks of 375 GB.

    For example, to attach two Local SSD disks to the machine type that you want to reserve while specifying two consumer projects, make a request as follows:

    POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/reservations
    
    {
      "name": "RESERVATION_NAME",
      "shareSettings": {
        "shareType": "SPECIFIC_PROJECTS",
        "projectMap": {
          "CONSUMER_PROJECT_ID_1": {
            "projectId": "CONSUMER_PROJECT_ID_1"
          },
          "CONSUMER_PROJECT_ID_2": {
            "projectId": "CONSUMER_PROJECT_ID_2"
          }
        }
      },
      "specificReservation": {
        "count": "NUMBER_OF_VMS",
        "instanceProperties": {
          "localSsds": [
            {
              "diskSizeGb": "375",
              "interface": "INTERFACE_TYPE"
            },
            {
              "diskSizeGb": "375",
              "interface": "INTERFACE_TYPE"
            }
          ],
          "machineType": "MACHINE_TYPE"
        }
      }
    }
    

    Replace INTERFACE_TYPE with the type of disk interface that you want each Local SSD disk to use and that your specified machine type supports. Specify one of the following values:

    • For the NVME disk interface: NVME

    • For the SCSI disk interface: SCSI

  • To have the reserved VMs use a specific minimum CPU platform instead of the zone's default CPU platform, include the minCpuPlatform field in the request body.

    For example, to create a shared reservation while specifying a minimum CPU platform and two consumer projects, make a request as follows:

    POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/reservations
    
    {
      "name": "RESERVATION_NAME",
      "shareSettings": {
        "shareType": "SPECIFIC_PROJECTS",
        "projectMap": {
          "CONSUMER_PROJECT_ID_1": {
            "projectId": "CONSUMER_PROJECT_ID_1"
          },
          "CONSUMER_PROJECT_ID_2": {
            "projectId": "CONSUMER_PROJECT_ID_2"
          }
        }
      },
      "specificReservation": {
        "count": "NUMBER_OF_VMS",
        "instanceProperties": {
          "machineType": "MACHINE_TYPE",
          "minCpuPlatform": "MIN_CPU_PLATFORM"
        }
      }
    }
    

    Replace MIN_CPU_PLATFORM with a minimum CPU platform. To make sure that a CPU platform is available in the zone where you're reserving resources, view the available CPU platforms by zone.

  • To specify that only VMs that specifically target this reservation can consume it, include the specificReservationRequired field in the request body, and set the field to true.

    For example, to create a specific reservation and share it with two consumer projects, make a request as follows:

    POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/reservations
    
    {
      "name": "RESERVATION_NAME",
      "shareSettings": {
        "shareType": "SPECIFIC_PROJECTS",
        "projectMap": {
          "CONSUMER_PROJECT_ID_1": {
            "projectId": "CONSUMER_PROJECT_ID_1"
          },
          "CONSUMER_PROJECT_ID_2": {
            "projectId": "CONSUMER_PROJECT_ID_2"
          }
        }
      },
      "specificReservation": {
        "count": "NUMBER_OF_VMS",
        "instanceProperties": {
          "machineType": "MACHINE_TYPE"
        }
      },
      "specificReservationRequired": true
    }
    
  • To let custom training jobs or prediction jobs in Vertex AI consume a reservation of GPU VMs, include the serviceShareType field and set it to ALLOW_ALL.

    POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/reservations
    
    {
      "name": "RESERVATION_NAME",
      "reservationSharingPolicy": {
        "serviceShareType": "ALLOW_ALL"
      },
      "shareSettings": {
        "shareType": "SPECIFIC_PROJECTS",
        "projectMap": {
          "CONSUMER_PROJECT_ID_1": {
            "projectId": "CONSUMER_PROJECT_ID_1"
          },
          "CONSUMER_PROJECT_ID_2": {
            "projectId": "CONSUMER_PROJECT_ID_2"
          }
        }
      },
      "specificReservation": {
        "count": "NUMBER_OF_VMS",
        "instanceProperties": {
          "machineType": "MACHINE_TYPE"
        }
      }
    }
    
  • To enable Compute Engine to automatically delete the reservation, select one of the following methods:

    • To delete the reservation at a specific date and time, make a POST request to the beta.reservations.insert method. In the request body, include the deleteAtTime field.

      For example, to create a reservation while specifying a date and time to delete a reservation, and share the reservation with two consumer projects, make a request as follows:

      POST https://compute.googleapis.com/compute/beta/projects/PROJECT_ID/zones/ZONE/reservations
      
      {
        "deleteAtTime": "DELETE_AT_TIME",
        "name": "RESERVATION_NAME",
        "shareSettings": {
          "shareType": "SPECIFIC_PROJECTS",
          "projectMap": {
            "CONSUMER_PROJECT_ID_1": {
              "projectId": "CONSUMER_PROJECT_ID_1"
            },
            "CONSUMER_PROJECT_ID_2": {
              "projectId": "CONSUMER_PROJECT_ID_2"
            }
          }
        },
        "specificReservation": {
          "count": "NUMBER_OF_VMS",
          "instanceProperties": {
            "machineType": "MACHINE_TYPE"
          }
        }
      }
      

      Replace DELETE_AT_TIME with a date and time formatted as an RFC 3339 timestamp, which must be as follows:

      YYYY-MM-DDTHH:MM:SSOFFSET
      

      Replace the following:

      • YYYY-MM-DD: a date formatted as a 4-digit year, 2-digit month, and a 2-digit day of the month, separated by hyphens (-).

      • HH:MM:SS: a time formatted as a 2-digit hour using a 24-hour time, 2-digit minutes, and 2-digit seconds, separated by colons (:).

      • OFFSET: the time zone formatted as an offset of Coordinated Universal Time (UTC). For example, to use the Pacific Standard Time (PST), specify -08:00. Alternatively, to use no offset, specify Z.

    • To delete the reservation after a specific duration, make a POST request to the beta.reservations.insert method. In the request body, include the deleteAfterDuration field.

      For example, to create a reservation that Compute Engine deletes after a specific duration, and share the reservation with two consumer projects, make a request as follows:

      POST https://compute.googleapis.com/compute/beta/projects/PROJECT_ID/zones/ZONE/reservations
      
      {
        "deleteAfterDuration": {
          "seconds": "DELETE_AFTER_DURATION"
        },
        "name": "RESERVATION_NAME",
        "shareSettings": {
          "shareType": "SPECIFIC_PROJECTS",
          "projectMap": {
            "CONSUMER_PROJECT_ID_1": {
              "projectId": "CONSUMER_PROJECT_ID_1"
            },
            "CONSUMER_PROJECT_ID_2": {
              "projectId": "CONSUMER_PROJECT_ID_2"
            }
          }
        },
        "specificReservation": {
          "count": "NUMBER_OF_VMS",
          "instanceProperties": {
            "machineType": "MACHINE_TYPE"
          }
        }
      }
      

      Replace DELETE_AFTER_DURATION with a duration in seconds. For example, specify 86400 for 86,400 seconds (1 day).

Troubleshooting

Learn how to troubleshoot reservation creation.

What's next

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026-02-20 UTC.