A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://cloud.google.com/compute/docs/instance-templates/create-instance-templates below:

Create instance templates | Compute Engine Documentation

Skip to main content Create instance templates

Stay organized with collections Save and categorize content based on your preferences.

This page describes how to create and manage instance templates. Instance templates let you specify the machine type, boot disk image, network, and other VM properties that you want to use when creating virtual machine (VM) instances.

You can use instance templates to do the following:

Before you begin Limitations Create an instance template

Most of the VM properties that you can specify in a request to create an individual VM instance can also be specified for an instance template, including any VM metadata, startup scripts, persistent disks, and service accounts. You must specify the machine type, boot disk, and network.

Create a regional or global instance template through the Google Cloud console, Google Cloud CLI, or the API. To create a global instance template, you can also use the Terraform or the Cloud Client Libraries.

Permissions required for this task

To perform this task, you must have the following permissions:

Console
  1. In the Google Cloud console, go to the Instance templates page.

    Go to Instance templates

    The remaining steps appear in the Google Cloud console.

  2. Click Create instance template .
  3. Select the Location as follows:
    1. If you want to use the instance template across regions, choose Global.
    2. If you want to reduce cross-region dependency, choose Regional.
  4. If you chose regional, then select the Region where you want to create your instance template.
  5. For the following fields, either accept the default values or modify them as required. The default values change based on the machine family that you select.

  6. Optional: If you chose an image that supports Shielded VM, change the VM's Shielded VM settings:

    1. Click Advanced options, and then click the Security tab.
    2. If you want to disable Secure Boot, clear the Turn on Secure Boot checkbox. Secure Boot helps protect your VM instances against boot-level and kernel-level malware and rootkits. For more information, see Secure boot.
    3. If you want to disable the virtual trusted platform module (vTPM), clear the Turn on vTPM checkbox. The vTPM enables Measured boot, which validates the VM pre-boot and boot integrity. For more information, see Virtual Trusted Platform Module (vTPM).

      Important: Disabling the vTPM also disables integrity monitoring because integrity monitoring relies on data gathered by Measured boot.
    4. If you want to disable integrity monitoring, uncheck the Turn on Integrity Monitoring checkbox. Integrity monitoring lets youn monitor the boot integrity of your Shielded VM instances by using Cloud Monitoring. For more information, see Integrity monitoring.

  7. Optional: Under Advanced options, click the tabs to further customize your template. For example, you can add up to 15 secondary non-boot disks.

  8. Optional: Click Equivalent REST to view the REST request body, which includes the JSON representation of your instance template.

  9. Click Create to create the template.

gcloud

To create a regional or global instance template, use the instance-templates create command. For a regional instance template, you must use the --instance-template-region flag to set the region of the template.

Create a regional instance template using the following command.

gcloud compute instance-templates create INSTANCE_TEMPLATE_NAME \
    --instance-template-region=REGION

Replace REGION with the region where you want to create the regional instance template.

Create a global instance template using the following command:

gcloud compute instance-templates create INSTANCE_TEMPLATE_NAME

If you don't provide explicit template settings, gcloud compute uses the following default values:

You can also explicitly provide these configuration settings. For example:

gcloud compute instance-templates create my-instance-template \
    --machine-type=e2-standard-4 \
    --image-family=debian-11 \
    --image-project=debian-cloud \
    --boot-disk-size=250GB

You can add up to 15 secondary non-boot disks. Specify the --create-disk flag for each secondary disk you create. To create secondary disks from a public or custom image, specify the image and image-project properties for each disk in the --create-disk flag. To create a blank disk, don't include these properties. Optionally, include properties for the disk size and type. To specify regional disks, use the replica-zones property.

gcloud compute instance-templates create INSTANCE_TEMPLATE_NAME \
    --machine-type=MACHINE_TYPE \
    --create-disk=image-family=DISK_IMAGE_FAMILY,image-project=DISK_IMAGE_PROJECT,size=SIZE_GB_DISK1 \
    --create-disk=device-name=DISK_NAME,type=DISK_TYPE,size=SIZE_GB_DISK2,replica-zones=^:^ZONE:REMOTE_ZONE,boot=false

Tip: When specifying the disk replica-zones parameter, the characters ^:^ specify that the separation character between values is a colon (:) instead of the expected comma (,).

Replace the following:

If you chose an image that supports Shielded VM, you can optionally change the instance's Shielded VM settings using one of the following flags:

For a list of all available subcommands and flags, see the instance-templates reference.

Terraform

To create an instance template, use one of the following resources:

The following example creates a global instance template:

To learn how to apply or remove a Terraform configuration, see Basic Terraform commands.

Go Java Node.js Python REST

To create a regional instance template, make a POST request to the regionInstanceTemplates.insert method as follows:

POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/instanceTemplates

To create a global instance template, make a POST request to the instanceTemplates.insert method:

POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/instanceTemplates

You can add up to 15 secondary non-boot disks by using the disks property, with a field for each additional disk. For each additional disk, you can do the following:

In the body of the request, provide the template properties:

{
  "name": "INSTANCE_TEMPLATE_NAME",
  "properties": {
    "machineType": "MACHINE_TYPE",
    "networkInterfaces": [
      {
        "network": "global/networks/default",
        "accessConfigs":
        [
          {
            "name": "external-IP",
            "type": "ONE_TO_ONE_NAT"
          }
        ]
      }
    ],
    "disks":
    [
      {
        "type": "PERSISTENT",
        "boot": true,
        "mode": "READ_WRITE",
        "initializeParams":
        {
          "sourceImage": "projects/IMAGE_PROJECT/global/images/IMAGE"
        }
      },
      {
        "type": "PERSISTENT",
        "boot": false,
        "deviceName": "DISK_NAME",
        "initializeParams":
        {
          "replicaZones": [
              "projects/PROJECT_NAME/zones/ZONE",
              "projects/PROJECT_NAME/zones/REMOTE_ZONE"
          ]
        }
      }
    ]
  }
}

Replace the following:

You can specify one of the following options for the disks property:

Optionally, you can specify the diskSizeGb, diskType, and labels properties for initializeParams and the diskSizeGb property for source.

If you chose an image that supports Shielded VM, you can optionally change the VM's Shielded VM settings by using the following Boolean request body items:

To learn more about request parameters, see the instanceTemplates.insert method.

Create an instance template based on an existing instance

You can use REST or gcloud CLI to save the configuration of an existing VM instance as an instance template. You can optionally override how the source disks are defined in the template.

If you need to override other properties, first create an instance template based on an existing instance, then create a similar template with additional overrides.

Warning: If the existing instance contains a static external IP address, that address is copied into the instance template and might limit the use of the template. Permissions required for this task

To perform this task, you must have the following permissions:

gcloud

Use the gcloud compute instance-templates create command with the --source-instance and --source-instance-zone flags. If you want to create a regional instance template, then you must also use the --instance-template-region flag to specify the region of the instance template.

To create a regional instance template, use the following command:

 gcloud compute instance-templates create INSTANCE_TEMPLATE_NAME \
     --source-instance=SOURCE_INSTANCE \
     --source-instance-zone=SOURCE_INSTANCE_ZONE \
     --instance-template-region=REGION

To create a global instance template, use the following command:

gcloud compute instance-templates create INSTANCE_TEMPLATE_NAME \
    --source-instance=SOURCE_INSTANCE \
    --source-instance-zone=SOURCE_INSTANCE_ZONE

To override how the source instance's disks are defined, add one or more --configure-disk flags.

The following example creates a global instance template from an existing instance and overrides the source instance's disk with the specifications that you provide.

  gcloud compute instance-templates create INSTANCE_TEMPLATE_NAME \
      --source-instance=SOURCE_INSTANCE \
      --source-instance-zone=SOURCE_INSTANCE_ZONE \
      --configure-disk= \
      device-name=SOURCE_DISK, \
      instantiate-from=INSTANTIATE_OPTIONS, \
      auto-delete=AUTO_DELETE

Replace the following:

For example, the following command creates an instance template based on my-source-instance, with the option to use the original image from data-disk-a, but set auto-delete to true and replace data-disk-b with a custom image.

 gcloud compute instance-templates create my-instance-template  \
     --source-instance=my-source-instance \
     --configure-disk=device-name=data-disk-a,instantiate-from=source-image,auto-delete=true \
     --configure-disk=device-name=data-disk-b,instantiate-from=custom-image,custom-image=projects/cps-cloud/global/images/cos-89-16108-403-15
Go Java Node.js Python REST

To create a regional instance template, use the regionInstanceTemplates.insert method, or, to create a global instance template, use the instanceTemplates.insert method.

In your request, you must specify the sourceInstance field. To override how the source instance's disks are defined, add one or more diskConfigs fields.

For example, make the following call to create a global instance template from an existing instance.

POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/instanceTemplates

{
  "name": "INSTANCE_TEMPLATE_NAME",
  "sourceInstance": "zones/SOURCE_INSTANCE_ZONE/instances/SOURCE_INSTANCE",
  "sourceInstanceParams": {
    "diskConfigs": [
      {
        "deviceName": "SOURCE_DISK",
        "instantiateFrom": "INSTANTIATE_OPTIONS",
        "autoDelete": false
      }
    ]
  }
}

Replace the following:

The following example creates a new instance template based on my-source-instance. In the instance template, the image for data-disk-a is replaced with projects/cos-cloud/global/images/cos-89-16108-403-15.

POST https://compute.googleapis.com/compute/v1/projects/my_project/global/instanceTemplates

{
  "name": "my-instance-template",
  "sourceInstance": "zones/us-central1-a/instances/my-source-instance",
  "sourceInstanceParams":
  {
    "diskConfigs":
    [
      {
        "deviceName": "data-disk-a",
        "instantiateFrom": "custom-image",
        "customImage": "projects/cos-cloud/global/images/cos-89-16108-403-15"
      }
    ]
  }
}

The following table shows how the options for overriding disks are defined in the template.

Disk type Options Boot disk Other read/write persistent disks Read-only disk(s) Local SSD(s)

For each disk, you can also override the auto-delete attribute to specify whether the disk should be deleted when its associated instance is deleted.

By default, if no override options are specified, the disk configuration in the template matches the source instance.

Create an instance template based on an existing template

You can't update an existing instance template. But, if an instance template goes out of date or if you need to make changes, you can create another one with similar properties by using the console.

  1. Go to the Instance templates page.

    Go to Instance templates

  2. Click the instance template that you want to copy and update.

  3. Click Create similar.

  4. Update the configuration in the new template.

  5. Click Create.

Create an instance template for GPU VMs

When creating an instance template, you can configure it for creating VMs that have attached GPUs by specifying the following:

Note: If you want to run data science or machine learning workloads, consider using a Deep Learning VM image when you create an instance template. Deep Learning VM Images is a set of prepackaged VM images that comes with machine learning frameworks and essential tools. For more information about these images, see Choose an image in the Deep Learning VM Images documentation. Permissions required for this task

To perform this task, you must have the following permissions:

Console

To create an instance template for GPU VMs, do the following:

  1. In the Google Cloud console, go to the Instance templates page.

    Go to Instance templates

  2. Click Create instance template.

  3. In the Name field, enter a name for the instance template.

  4. In the Location section, select one of the following options:

  5. In the Machine configuration section, do the following:

    1. Click the GPUs tab.

    2. In the GPU type menu, select the GPU type.

    3. In the Number of GPUs menu, select the number of GPUs.

    4. Optional: If your GPU model supports NVIDIA RTX Virtual Workstations (vWS) for graphics workloads, and you plan to run graphics-intensive workloads, select Enable Virtual Workstation (NVIDIA GRID).

    5. In the Machine type section, select a machine type.

  6. Optional: To change the default value boot disk type or image, in the Boot disk section, click Change. Then, follow the prompts to change the boot disk.

  7. Click Create.

gcloud

To create an instance template for GPU VMs, use the instance-templates create command with the --maintenance-policy flag set to TERMINATE.

For example, to create a global instance template for GPU VMs, use the following command:

gcloud compute instance-templates create INSTANCE_TEMPLATE_NAME \
    --image-project=IMAGE_PROJECT \
    --image-family=IMAGE_FAMILY \
    --machine-type=MACHINE_TYPE \
    --maintenance-policy=TERMINATE

Replace the following:

For example, assume that you want to create a global instance template for GPU VMs that specifies the following properties:

To create the example instance template, use the following command:

gcloud compute instance-templates create instance-template-gpu \
    --accelerator=count=1,type=nvidia-tesla-t4 \
    --machine-type=n1-standard-2 \
    --image-family=debian-10 \
    --image-project=debian-cloud \
    --maintenance-policy=TERMINATE
Terraform

To create an instance template, use one of the following resources:

The following example creates a global instance template that specifies an N1 predefined machine type with 2 vCPUs and one NVIDIA T4 GPU attached:

To learn how to apply or remove a Terraform configuration, see Basic Terraform commands.

REST

To create an instance template for GPU VMs, make a POST request to the instanceTemplates.insert method. In the request body, include the onHostMaintenance field and set it to TERMINATE.

For example, to create a global instance template for GPU VMs, make a POST request as follows:

POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/instanceTemplates

{
  "name": "INSTANCE_TEMPLATE_NAME",
  "properties": {
    "disks": [
      {
        "type": "PERSISTENT",
        "boot": true,
        "mode": "READ_WRITE",
        "initializeParams": {
          "sourceImage": "projects/IMAGE_PROJECT/global/images/IMAGE"
        }
      }
    ],
    "machineType": "MACHINE_TYPE",
    "networkInterfaces": [
      {
        "accessConfigs": [
          {
            "name": "external-IP",
            "type": "ONE_TO_ONE_NAT"
          }
        ],
        "network": "global/networks/default"
      }
    ],
    "scheduling": {
      "onHostMaintenance": "TERMINATE"
    }
  }
}

Replace the following:

For example, assume that you want to create a global instance template for GPU VMs that specifies the following properties:

To create the example instance template, make a POST request as follows:

POST https://compute.googleapis.com/compute/v1/projects/example-project/global/instanceTemplates

{
  "name": "instance-template-gpu",
  "properties": {
    "disks": [
      {
        "type": "PERSISTENT",
        "boot": true,
        "mode": "READ_WRITE",
        "initializeParams": {
          "sourceImage": "projects/debian-cloud/global/images/family/debian-10"
        }
      }
    ],
    "guestAccelerators": [
      {
        "acceleratorType": "nvidia-tesla-t4",
        "acceleratorCount": 1
      }
    ],
    "machineType": "n1-standard-2",
    "networkInterfaces": [
      {
        "accessConfigs": [
          {
            "name": "external-IP",
            "type": "ONE_TO_ONE_NAT"
          }
        ],
        "network": "global/networks/default"
      }
    ],
    "scheduling": {
      "onHostMaintenance": "TERMINATE"
    }
  }
}

For more configuration options when creating an instance template, see Create an instance template in this document.

Create an instance template with a container image Note: The Compute Engine feature that deploys containers on VMs during VM creation is deprecated. Use the docker run commands in a startup script or use the cloud-init tool to configure and to run containers on your VMs and MIGs. For more information, see Migrate containers that were deployed on VMs during VM creation.

You can specify a container image in an instance template. By default, Compute Engine also includes in the template a Container-Optimized OS image with Docker installed. When you use the template to create a new instance, the container is launched automatically as the instance starts up.

Console Note: The Deploy container option in the Google Cloud console is deprecated. Use the equivalent docker run command to configure and to run the container.
  1. Go to the Instance templates page.

    Go to Instance templates

  2. Click Create instance template.

  3. In the Container section, click Deploy Container.

  4. In the Configure container dialog, specify the Container image to use.

  5. Optionally, click Advanced container options. For more information, see Configuring options to run your Container.

  6. Click Create.

gcloud Note: The create-with-container gcloud CLI command is deprecated. Use the equivalent docker run command to configure and to run the container.

Use the gcloud compute instance-templates create-with-container command:

 gcloud compute instance-templates create-with-container INSTANCE_TEMPLATE_NAME \
     --container-image=CONTAINER_IMAGE

Replace the following:

For example, the following command creates a new instance template named nginx-vm. A VM instance created from this template launches and runs the container image, gcr.io/cloud-marketplace/google/nginx1:TAG, when the VM starts.

 gcloud compute instance-templates create-with-container nginx-vm \
     --container-image=gcr.io/cloud-marketplace/google/nginx1:TAG

Replace TAG with the tag defined for a specific version of NGINX container image available on Google Cloud Marketplace.

You can also configure options to run your container.

Caution: Container Registry is deprecated. Effective March 18, 2025, Container Registry is shut down, and writing images to Container Registry is unavailable. For details on the deprecation and how to migrate to Artifact Registry, see Container Registry deprecation.

Create an instance template that specifies a subnet gcloud

To create a regional or global instance template, use the instance-templates create command. Use the --subnet flag to place instances that are created from the template into the subnet of your choice. The --subnet flag requires the --region flag.

If you want to create a regional instance template, you must use the --instance-template-region flag to set the region of the template. Make sure that you use a subnet from the same region as where you want to create the regional instance template.

gcloud compute instance-templates create INSTANCE_TEMPLATE_NAME \
    --region=REGION \
    --subnet=SUBNET_NAME_OR_URL \
    --stack-type=STACK_TYPE \
    --instance-template-region=INSTANCE_TEMPLATE_REGION

Replace the following:

The following example creates a template called template-qa that only creates instances in the subnet-us-qa subnet.

gcloud compute instance-templates create template-qa \
    --region=us-central1 \
    --subnet=subnet-us-qa

The output is similar to the following:

Created [https://compute.googleapis.com/compute/latest/projects/PROJECT_ID/global/instanceTemplates/template-qa].
NAME        MACHINE_TYPE        PREEMPTIBLE CREATION_TIMESTAMP
template-qa e2-standard-2       2019-12-23T20:34:00.791-07:00

Go Java Node.js Python

Using this template to create instances for a MIG (with or without autoscaling) automatically creates the instance in the specified region and subnet. This lets you control the subnet of new instances created for load balancing.

Use custom or public images in your instance templates

You can either use a custom image or a public image for your instance templates:

Custom images are more deterministic and start more quickly than VMs with startup scripts. However, startup scripts are more flexible, which helps you update the apps and settings in your instances.

If you're managing images using image families, you can specify the name of your custom or public image family in the instance template. For more information on image families, see best practices when using image families on Compute Engine.

Note: If the image you want to use belongs to a different project, you can still use that image in your instance template, provided that the owner of that project grants the MIG access to the images. For more information, see Granting a MIG access to images. 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 2025-08-07 UTC.

[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[[["Instance templates define VM properties like machine type, boot disk, and network settings, enabling the creation of individual VMs, managed instance groups (MIGs), and reservations."],["You can create instance templates using various methods such as the Google Cloud console, gcloud CLI, Terraform, or programmatically with Go, Java, Node.js, Python, and REST, with the templates being either global or regional."],["Instance templates cannot be updated; to implement any change, a new instance template must be created, however, you can create a template from an existing instance or an existing template."],["Instance templates can specify subnet details, ensuring VMs are created within a specific network environment, which is useful for creating managed instance groups."],["Instance templates can be used to create specialized VMs such as GPU-enabled VMs and VMs with container images, and can include custom images or public images with startup scripts."]]],[]]


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4