Creating Instance Templates

This page describes how to create and manage instance templates. Instance templates allow you to define the machine type, image, network and other instance properties to use when creating new VM instances. You can use instance templates to create instances in a managed instance group or to create individual instances.

Before you begin

Creating a new instance template

Most of the instance properties that you can define in a regular API request to create an individual VM instance can be defined in the instance template, including any instance metadata, startup scripts, persistent disks, service accounts, and so on.

At a minimum, the same required properties for creating an instance are also required to create an instance template. See a list of the required fields on the instanceTemplates().insert reference.

Create an instance template through the Google Cloud Platform Console, gcloud compute tool, or the API.


  1. In the GCP Console, go to the Instance Templates page.

    Go to the Instance templates page

  2. Click Create instance template.
  3. Fill in the fields you want for your instance template, or accept the default values. The following values are provided by default:

    • Machine type: n1-standard-1
    • Image: The latest Debian image
    • Boot disk: A new standard boot disk named after the instance
    • VPC network: The default VPC network
    • IP address: An ephemeral external IP address
  4. Click Create to create the template.


In gcloud compute, create an instance template using the instance-templates create command:

gcloud compute instance-templates create [INSTANCE_TEMPLATE_NAME]

where you replace [INSTANCE_TEMPLATE_NAME] with the desired name of the instance template.

If you do not provide explicit template settings, gcloud compute creates a template with the following default values:

  • Machine type: n1-standard-1
  • Image: The latest Debian image
  • Boot disk: A new standard boot disk named after the instance
  • Network: The default VPC network
  • IP address: An ephemeral external IP address

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

gcloud compute instance-templates create example-template-custom \
    --machine-type n1-standard-4 \
    --image-family debian-9 \
    --image-project debian-cloud \
    --boot-disk-size 250GB

You can see a list of available flags in the gcloud compute reference.

A template with the default configuration settings might look like the following:

gcloud compute instance-templates describe example-template

creationTimestamp: '2014-09-10T16:18:32.042-07:00'
description: ''
id: '6057583701980539406'
kind: compute#instanceTemplate
name: example-template
  canIpForward: false
  - autoDelete: true
    boot: true
    kind: compute#attachedDisk
    mode: READ_WRITE
    type: PERSISTENT
  machineType: n1-standard-1
  - accessConfigs:
    - kind: compute#accessConfig
      name: external-nat
      type: ONE_TO_ONE_NAT
    automaticRestart: true
    onHostMaintenance: MIGRATE
  - email: default


In the instance template API, you must explicitly define all of the required configuration fields as described in the instanceTemplates().insert documentation. For example, an instance template with the minimal required fields looks like the following:

"name": "example-template",
"properties": {
  "machineType": "zones/us-central1-a/machineTypes/n1-standard-4",
  "networkInterfaces": [
      "network": "global/networks/default",
          "name": "external-IP",
          "type": "ONE_TO_ONE_NAT"
      "type": "PERSISTENT",
      "boot": true,
      "mode": "READ_WRITE",
        "sourceImage": "projects/debian-cloud/global/images/family/debian-9"

For the disks property, you must either provide the initializeParams property to create new persistent boot disks for each instance, or you can provide the source property to attach an existing persistent boot disk. If you attach an existing boot disk, you can only create one instance from your template.

Creating an instance template based on an existing instance

You can use the --source-instance flag to save the configuration of an existing virtual machine instance into an instance template. Optionally, you can override how the source disks for the instance are defined in the template.

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

Disk type Options
Boot disk
  • [Default] Use the same source image or image family that was used to create the boot disk in the source instance.
  • Use the URL of any (custom or public) image.
Other read-write persistent disk(s)
  • [Default] Use the same source image/source image family that was used to create the disk in the source instance. Note: If the source instance's disk does not have a source image/source image family property, then it will not be included.
  • Use the URL of any (custom or public) image.
  • Do not include the disk.
Read-only disk(s)
  • [Default] Include the disk in read-only mode.
  • Do not include the disk.
Local SSD(s)
  • [Default] Include a blank local SSD

For each disk, you can also override the auto-delete attribute to specify whether or not 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.


For a list of all the flags, see the gcloud beta instance-templates create command.

gcloud beta 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_FROM], \


  • [INSTANCE_TEMPLATE_NAME] is the name of the template to create.
  • [SOURCE_INSTANCE] is the name of the instance to use as a model for the new template.
  • [SOURCE_INSTANCE_ZONE] is the zone that contains the source instance.
  • [SOURCE_DISK] is the name of a source-instance disk that you want to override within the template.
  • [INSTANTIATE_FROM] specifies whether to include the disk and which image to use. Valid values depend on the type of disk:
    • source-image or source-image-family (valid only for boot and other persistent read-write disks).
    • custom-image (valid only for boot and other persistent read-write disks). If specified then the path or URL for the custom image must also be specified; see example below.
    • attach-read-only (valid only for read-only disks).
    • do-not-include (valid only for non-boot persistent disks and read-only disks).
  • [AUTO_DELETE] specifies whether the disk will be auto-deleted when the instance is deleted. Valid values are: false, no, true, and yes.

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 to replace data-disk-b with a custom image.

gcloud compute instance-templates create my-instance-template  \
    --source-instance my-source-instance \
    --configure-disk=source-disk=data-disk-a,instantiate-from=source-image, \
    --configure-disk=source-disk=data-disk-b,instantiate-from=custom-image, \


For a list of all the flags, see the InstanceTemplates API docs.

  "sourceInstance": "zones/[SOURCE_INSTANCE_ZONE]/instances/[SOURCE_INSTANCE]"


  • [PROJECT_ID] with the project ID for the request.
  • [INSTANCE_TEMPLATE_NAME] with the name of the new template.
  • [SOURCE_INSTANCE_ZONE] with the zone of the source instance.
  • [SOURCE_INSTANCE] with the name of the source instance to use as a model for this instance template.

The following example creates a new instance template based on my-source-instance. It saves the source image of data-disk-a in the instance template and sets its autoDelete attribute to true.

  "name": "my-instance-template",
  "sourceInstance": "zones/us-central1-a/instances/my-source-instance",
  “sourceInstanceParams” : {
    "diskConfiguration": [
        "deviceName" : "data-disk-a",
        "instantiateFrom" : "SOURCE_IMAGE",
        "autoDelete” : true

Creating an instance template that specifies a subnet

Instance template commands have --subnet and --region flags that place new instances into the subnet of your choice. The --subnet flag requires the --region flag.

gcloud compute instance-templates create [INSTANCE_TEMPLATE_NAME] \
    --region [REGION] \
    --subnet [SUBNET_NAME_OR_URL]

where you replace the following:

  • [INSTANCE_TEMPLATE_NAME] with the desired name of the instance template.
  • [REGION] with the region of the subnet.
  • [SUBNET_NAME_OR_URL] with either the name of the subnet or its URL. Note: if you use the subnet name, Google will find that subnet in the target region (provided that it exists there); however, if you use the subnet URL, then the instance template can only be used to create instances in the specific region that is associated with the subnet URL.

This 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
Created [].
template-qa n1-standard-1             2015-12-23T20:34:00.791-07:00

Using this template to create instances for a Managed Instance Group (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.

Using custom or public images in your instance templates

Because managed instance groups are designed to add and remove instances frequently, it is useful to create a custom image and specify it in the instance template. Prepare your image with the applications and settings that your instances need so you don't have to manually configure those items on individual instances in the managed instance group.

Alternatively, you can create an instance template that uses a public image and a startup script to prepare the instance after it starts running. Custom images are more deterministic and start more quickly than instances with startup scripts. However, startup scripts are more flexible and allow you to update the applications and settings in your instances more easily.

Updating an instance template

It is not possible to update an existing instance template or change an instance template after it has been created. If an instance template goes out of date, or you need to make changes to the configuration, create a new instance template.

What's next

Send feedback about...

Compute Engine Documentation