Google Compute Engine Instance Template

This page shows how to write Terraform for Compute Engine Instance Template and write them securely.

google_compute_instance_template (Terraform)

The Instance Template in Compute Engine can be configured in Terraform with the resource name google_compute_instance_template. The following sections describe 4 examples of how to use the resource and its parameters.

Example Usage from GitHub
resource "google_compute_instance_template" "gcloud_no_args" {
  name         = "gcloud-no-args"
  machine_type = "n1-standard-1"

  disk {
    source_image = "debian-cloud/debian-10"
resource "google_compute_instance_template" "default" {
  name        = "us-central1-template"
  description = "This template is used to create app server instances."
  machine_type= "e2-medium"
  region = "us-central1"
  disk {
resource "google_compute_instance_template" "browse_asia" {
  name         = "browse-asia"
  region       =
  machine_type =

  tags = ["web", "lockdown"]
resource "google_compute_instance_template" "tf-server-staging" {
  name = "tf-server-staging"
  project = "comp698-dml1037"
  disk {
    source_image = "cos-cloud/cos-stable"


  • can_ip_forward optional - bool
    • Whether to allow sending and receiving of packets with non-matching source or destination IPs. This defaults to false.

  • description optional - string
    • A brief description of this resource.

  • enable_display optional - bool
    • Enable Virtual Displays on this instance. Note: allow_stopping_for_update must be set to true in order to update this field.

  • id optionalcomputed - string
  • instance_description optional - string
    • A description of the instance.

  • labels optional - map / string
    • A set of key/value label pairs to assign to instances created from this template,

  • machine_type required - string
    • The machine type to create. To create a machine with a custom type (such as extended memory), format the value like custom-VCPUS-MEM_IN_MB like custom-6-20480 for 6 vCPU and 20GB of RAM.

  • metadata optional - map / string
    • Metadata key/value pairs to make available from within instances created from this template.

  • metadata_fingerprint requiredcomputed - string
    • The unique fingerprint of the metadata.

  • metadata_startup_script optional - string
    • An alternative to using the startup-script metadata key, mostly to match the compute_instance resource. This replaces the startup-script metadata key on the created instance and thus the two mechanisms are not allowed to be used simultaneously.

  • min_cpu_platform optional - string
    • Specifies a minimum CPU platform. Applicable values are the friendly names of CPU platforms, such as Intel Haswell or Intel Skylake.

  • name optionalcomputed - string
    • The name of the instance template. If you leave this blank, Terraform will auto-generate a unique name.

  • name_prefix optionalcomputed - string
    • Creates a unique name beginning with the specified prefix. Conflicts with name.

  • project optionalcomputed - string
    • The ID of the project in which the resource belongs. If it is not provided, the provider project is used.

  • region optionalcomputed - string
    • An instance template is a global resource that is not bound to a zone or a region. However, you can still specify some regional resources in an instance template, which restricts the template to the region where that resource resides. For example, a custom subnetwork resource is tied to a specific region. Defaults to the region of the Provider if no value is given.

  • self_link requiredcomputed - string
    • The URI of the created resource.

  • tags optional - set / string
    • Tags to attach to the instance.

  • tags_fingerprint requiredcomputed - string
    • The unique fingerprint of the tags.

Explanation in Terraform Registry

Manages a VM instance template resource within GCE. For more information see the official documentation and API.

Frequently asked questions

What is Google Compute Engine Instance Template?

Google Compute Engine Instance Template is a resource for Compute Engine of Google Cloud Platform. Settings can be wrote in Terraform.

Where can I find the example code for the Google Compute Engine Instance Template?

For Terraform, the bleything/gcp-terraform-snippets, PhaniVemuri912/gcp-sg-01 and kaysal/cloud-networking source code examples are useful. See the Terraform Example section for further details.


Scan your IaC problem in 3 minutes for free

You can keep your IaC security for free. No credit card required.