FEATURES OPEN SOURCE ABOUT DOCS LOGIN REGISTER

google_compute_instance_template

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

Example Usage

resource "google_compute_instance_template" "foobar" {
  name        = "terraform-test"
  description = "template description"

  tags = ["foo", "bar"]

  instance_description = "description assigned to instances"
  machine_type         = "n1-standard-1"
  can_ip_forward       = false
  automatic_restart    = true
  on_host_maintenance  = "MIGRATE"

  // Create a new boot disk from an image
  disk {
    source_image = "debian-cloud/debian-8"
    auto_delete = true
    boot = true
  }

  // Use an existing disk resource
  disk {
    source      = "foo_existing_disk"
    auto_delete = false
    boot        = false
  }

  network_interface {
    network = "default"
  }

  metadata {
    foo = "bar"
  }

  service_account {
    scopes = ["userinfo-email", "compute-ro", "storage-ro"]
  }
}

Using with Instance Group Manager

Instance Templates cannot be updated after creation with the Google Cloud Platform API. In order to update an Instance Template, Terraform will destroy the existing resource and create a replacement. In order to effectively use an Instance Template resource with an Instance Group Manager resource, it’s recommended to specify create_before_destroy in a lifecycle block. Either omit the Instance Template name attribute, or specify a partial name with name_prefix. Example:

resource "google_compute_instance_template" "instance_template" {
    name_prefix = "instance-template-"
    machine_type = "n1-standard-1"
    region = "us-central1"

    // boot disk
    disk {
      ...
    }

    // networking
    network_interface {
      ...
    }

    lifecycle {
        create_before_destroy = true
    }
}

resource "google_compute_instance_group_manager" "instance_group_manager" {
    name = "instance-group-manager"
    instance_template = "${google_compute_instance_template.instance_template.self_link}"
    base_instance_name = "instance-group-manager"
    zone = "us-central1-f"
    target_size = "1"
}

With this setup Terraform generates a unique name for your Instance Template and can then update the Instance Group manager without conflict before destroying the previous Instance Template.

Argument Reference

Note that changing any field for this resource forces a new resource to be created.

The following arguments are supported:


The disk block supports:

The network_interface block supports:

The access_config block supports:

The service_account block supports:

The scheduling block supports:

Attributes Reference

In addition to the arguments listed above, the following computed attributes are exported:


See the source of this document at Terraform.io