github.com/vtorhonen/terraform@v0.9.0-beta2.0.20170307220345-5d894e4ffda7/website/source/docs/providers/google/r/compute_instance_template.html.markdown (about)

     1  ---
     2  layout: "google"
     3  page_title: "Google: google_compute_instance_template"
     4  sidebar_current: "docs-google-compute-instance-template"
     5  description: |-
     6    Manages a VM instance template resource within GCE.
     7  ---
     8  
     9  
    10  # google\_compute\_instance\_template
    11  
    12  Manages a VM instance template resource within GCE. For more information see
    13  [the official documentation](https://cloud.google.com/compute/docs/instance-templates)
    14  and
    15  [API](https://cloud.google.com/compute/docs/reference/latest/instanceTemplates).
    16  
    17  
    18  ## Example Usage
    19  
    20  ```js
    21  resource "google_compute_instance_template" "foobar" {
    22    name        = "terraform-test"
    23    description = "template description"
    24  
    25    tags = ["foo", "bar"]
    26  
    27    instance_description = "description assigned to instances"
    28    machine_type         = "n1-standard-1"
    29    can_ip_forward       = false
    30  
    31    scheduling {
    32      automatic_restart   = true
    33      on_host_maintenance = "MIGRATE"
    34    }
    35  
    36    // Create a new boot disk from an image
    37    disk {
    38      source_image = "debian-cloud/debian-8"
    39      auto_delete  = true
    40      boot         = true
    41    }
    42  
    43    // Use an existing disk resource
    44    disk {
    45      source      = "foo_existing_disk"
    46      auto_delete = false
    47      boot        = false
    48    }
    49  
    50    network_interface {
    51      network = "default"
    52    }
    53  
    54    metadata {
    55      foo = "bar"
    56    }
    57  
    58    service_account {
    59      scopes = ["userinfo-email", "compute-ro", "storage-ro"]
    60    }
    61  }
    62  ```
    63  
    64  ## Using with Instance Group Manager
    65  
    66  Instance Templates cannot be updated after creation with the Google
    67  Cloud Platform API. In order to update an Instance Template, Terraform will
    68  destroy the existing resource and create a replacement. In order to effectively
    69  use an Instance Template resource with an [Instance Group Manager resource][1],
    70  it's recommended to specify `create_before_destroy` in a [lifecycle][2] block.
    71  Either omit the Instance Template `name` attribute, or specify a partial name
    72  with `name_prefix`.  Example:
    73  
    74  ```
    75  resource "google_compute_instance_template" "instance_template" {
    76    name_prefix  = "instance-template-"
    77    machine_type = "n1-standard-1"
    78    region       = "us-central1"
    79  
    80    // boot disk
    81    disk {
    82      # ...
    83    }
    84  
    85    // networking
    86    network_interface {
    87      # ...
    88    }
    89  
    90    lifecycle {
    91      create_before_destroy = true
    92    }
    93  }
    94  
    95  resource "google_compute_instance_group_manager" "instance_group_manager" {
    96    name               = "instance-group-manager"
    97    instance_template  = "${google_compute_instance_template.instance_template.self_link}"
    98    base_instance_name = "instance-group-manager"
    99    zone               = "us-central1-f"
   100    target_size        = "1"
   101  }
   102  ```
   103  
   104  With this setup Terraform generates a unique name for your Instance
   105  Template and can then update the Instance Group manager without conflict before
   106  destroying the previous Instance Template.
   107  
   108  
   109  ## Argument Reference
   110  
   111  Note that changing any field for this resource forces a new resource to be created.
   112  
   113  The following arguments are supported:
   114  
   115  * `disk` - (Required) Disks to attach to instances created from this template.
   116      This can be specified multiple times for multiple disks. Structure is
   117      documented below.
   118  
   119  * `machine_type` - (Required) The machine type to create.
   120  
   121  - - -
   122  * `name` - (Optional) The name of the instance template. If you leave
   123    this blank, Terraform will auto-generate a unique name.
   124  
   125  * `name_prefix` - (Optional) Creates a unique name beginning with the specified
   126    prefix. Conflicts with `name`.
   127  
   128  * `can_ip_forward` - (Optional) Whether to allow sending and receiving of
   129      packets with non-matching source or destination IPs. This defaults to false.
   130  
   131  * `description` - (Optional) A brief description of this resource.
   132  
   133  * `instance_description` - (Optional) A brief description to use for instances
   134      created from this template.
   135  
   136  * `metadata` - (Optional) Metadata key/value pairs to make available from
   137      within instances created from this template.
   138  
   139  * `metadata_startup_script` - (Optional) An alternative to using the
   140      startup-script metadata key, mostly to match the compute_instance resource.
   141      This replaces the startup-script metadata key on the created instance and
   142      thus the two mechanisms are not allowed to be used simultaneously.
   143  
   144  * `network_interface` - (Required) Networks to attach to instances created from
   145      this template. This can be specified multiple times for multiple networks.
   146      Structure is documented below.
   147  
   148  * `project` - (Optional) The project in which the resource belongs. If it
   149      is not provided, the provider project is used.
   150  
   151  * `region` - (Optional) An instance template is a global resource that is not
   152      bound to a zone or a region. However, you can still specify some regional
   153      resources in an instance template, which restricts the template to the
   154      region where that resource resides. For example, a custom `subnetwork`
   155      resource is tied to a specific region. Defaults to the region of the
   156      Provider if no value is given.
   157  
   158  * `scheduling` - (Optional) The scheduling strategy to use. More details about
   159      this configuration option are detailed below.
   160  
   161  * `service_account` - (Optional) Service account to attach to the instance. Structure is documented below.
   162  
   163  * `tags` - (Optional) Tags to attach to the instance.
   164  
   165  The `disk` block supports:
   166  
   167  * `auto_delete` - (Optional) Whether or not the disk should be auto-deleted.
   168      This defaults to true.
   169  
   170  * `boot` - (Optional) Indicates that this is a boot disk.
   171  
   172  * `device_name` - (Optional) A unique device name that is reflected into the
   173      /dev/  tree of a Linux operating system running within the instance. If not
   174      specified, the server chooses a default device name to apply to this disk.
   175  
   176  * `disk_name` - (Optional) Name of the disk. When not provided, this defaults
   177      to the name of the instance.
   178  
   179  * `source_image` - (Required if source not set) The name of the image to base
   180      this disk off of. Accepts same arguments as a [google_compute_instance image](https://www.terraform.io/docs/providers/google/r/compute_instance.html#image).
   181  
   182  * `interface` - (Optional) Specifies the disk interface to use for attaching
   183      this disk.
   184  
   185  * `mode` - (Optional) The mode in which to attach this disk, either READ_WRITE
   186      or READ_ONLY. If you are attaching or creating a boot disk, this must
   187      read-write mode.
   188  
   189  * `source` - (Required if source_image not set) The name of the disk (such as
   190      those managed by `google_compute_disk`) to attach.
   191  
   192  * `disk_type` - (Optional) The GCE disk type. Can be either `"pd-ssd"`,
   193      `"local-ssd"`, or `"pd-standard"`.
   194  
   195  * `disk_size_gb` - (Optional) The size of the image in gigabytes. If not
   196      specified, it will inherit the size of its base image.
   197  
   198  * `type` - (Optional) The type of GCE disk, can be either `"SCRATCH"` or
   199      `"PERSISTENT"`.
   200  
   201  The `network_interface` block supports:
   202  
   203  * `network` - (Optional) The name or self_link of the network to attach this interface to.
   204      Use `network` attribute for Legacy or Auto subnetted networks and
   205      `subnetwork` for custom subnetted networks.
   206  
   207  * `subnetwork` - (Optional) the name of the subnetwork to attach this interface
   208      to. The subnetwork must exist in the same `region` this instance will be
   209      created in. Either `network` or `subnetwork` must be provided.
   210  
   211  * `subnetwork_project` - (Optional) The project in which the subnetwork belongs.
   212      If it is not provided, the provider project is used.
   213  
   214  * `access_config` - (Optional) Access configurations, i.e. IPs via which this
   215      instance can be accessed via the Internet. Omit to ensure that the instance
   216      is not accessible from the Internet (this means that ssh provisioners will
   217      not work unless you are running Terraform can send traffic to the instance's
   218      network (e.g. via tunnel or because it is running on another cloud instance
   219      on that network). This block can be repeated multiple times. Structure documented below.
   220  
   221  The `access_config` block supports:
   222  
   223  * `nat_ip` - (Optional) The IP address that will be 1:1 mapped to the instance's
   224      network ip. If not given, one will be generated.
   225  
   226  The `service_account` block supports:
   227  
   228  * `email` - (Optional) The service account e-mail address. If not given, the
   229      default Google Compute Engine service account is used.
   230  
   231  * `scopes` - (Required) A list of service scopes. Both OAuth2 URLs and gcloud
   232      short names are supported.
   233  
   234  The `scheduling` block supports:
   235  
   236  * `automatic_restart` - (Optional) Specifies whether the instance should be
   237      automatically restarted if it is terminated by Compute Engine (not
   238      terminated by a user). This defaults to true.
   239  
   240  * `on_host_maintenance` - (Optional) Defines the maintenance behavior for this
   241      instance.
   242  
   243  * `preemptible` - (Optional) Allows instance to be preempted. This defaults to
   244      false. Read more on this
   245      [here](https://cloud.google.com/compute/docs/instances/preemptible).
   246  
   247  ## Attributes Reference
   248  
   249  In addition to the arguments listed above, the following computed attributes are
   250  exported:
   251  
   252  * `metadata_fingerprint` - The unique fingerprint of the metadata.
   253  
   254  * `self_link` - The URI of the created resource.
   255  
   256  * `tags_fingerprint` - The unique fingerprint of the tags.
   257  
   258  [1]: /docs/providers/google/r/compute_instance_group_manager.html
   259  [2]: /docs/configuration/resources.html#lifecycle