github.com/nathanielks/terraform@v0.6.1-0.20170509030759-13e1a62319dc/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  ```hcl
    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  ```hcl
    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 image from which to
   180      initialize this disk. This can be one of: the image's `self_link`,
   181      `projects/{project}/global/images/{image}`,
   182      `projects/{project}/global/images/family/{family}`, `global/images/{image}`,
   183      `global/images/family/{family}`, `family/{family}`, `{project}/{family}`,
   184      `{project}/{image}`, `{family}`, or `{image}`.
   185  
   186  * `interface` - (Optional) Specifies the disk interface to use for attaching
   187      this disk.
   188  
   189  * `mode` - (Optional) The mode in which to attach this disk, either READ_WRITE
   190      or READ_ONLY. If you are attaching or creating a boot disk, this must
   191      read-write mode.
   192  
   193  * `source` - (Required if source_image not set) The name of the disk (such as
   194      those managed by `google_compute_disk`) to attach.
   195  
   196  * `disk_type` - (Optional) The GCE disk type. Can be either `"pd-ssd"`,
   197      `"local-ssd"`, or `"pd-standard"`.
   198  
   199  * `disk_size_gb` - (Optional) The size of the image in gigabytes. If not
   200      specified, it will inherit the size of its base image.
   201  
   202  * `type` - (Optional) The type of GCE disk, can be either `"SCRATCH"` or
   203      `"PERSISTENT"`.
   204  
   205  The `network_interface` block supports:
   206  
   207  * `network` - (Optional) The name or self_link of the network to attach this interface to.
   208      Use `network` attribute for Legacy or Auto subnetted networks and
   209      `subnetwork` for custom subnetted networks.
   210  
   211  * `subnetwork` - (Optional) the name of the subnetwork to attach this interface
   212      to. The subnetwork must exist in the same `region` this instance will be
   213      created in. Either `network` or `subnetwork` must be provided.
   214  
   215  * `subnetwork_project` - (Optional) The project in which the subnetwork belongs.
   216      If it is not provided, the provider project is used.
   217  
   218  * `access_config` - (Optional) Access configurations, i.e. IPs via which this
   219      instance can be accessed via the Internet. Omit to ensure that the instance
   220      is not accessible from the Internet (this means that ssh provisioners will
   221      not work unless you are running Terraform can send traffic to the instance's
   222      network (e.g. via tunnel or because it is running on another cloud instance
   223      on that network). This block can be repeated multiple times. Structure documented below.
   224  
   225  The `access_config` block supports:
   226  
   227  * `nat_ip` - (Optional) The IP address that will be 1:1 mapped to the instance's
   228      network ip. If not given, one will be generated.
   229  
   230  The `service_account` block supports:
   231  
   232  * `email` - (Optional) The service account e-mail address. If not given, the
   233      default Google Compute Engine service account is used.
   234  
   235  * `scopes` - (Required) A list of service scopes. Both OAuth2 URLs and gcloud
   236      short names are supported.
   237  
   238  The `scheduling` block supports:
   239  
   240  * `automatic_restart` - (Optional) Specifies whether the instance should be
   241      automatically restarted if it is terminated by Compute Engine (not
   242      terminated by a user). This defaults to true.
   243  
   244  * `on_host_maintenance` - (Optional) Defines the maintenance behavior for this
   245      instance.
   246  
   247  * `preemptible` - (Optional) Allows instance to be preempted. This defaults to
   248      false. Read more on this
   249      [here](https://cloud.google.com/compute/docs/instances/preemptible).
   250  
   251  ## Attributes Reference
   252  
   253  In addition to the arguments listed above, the following computed attributes are
   254  exported:
   255  
   256  * `metadata_fingerprint` - The unique fingerprint of the metadata.
   257  
   258  * `self_link` - The URI of the created resource.
   259  
   260  * `tags_fingerprint` - The unique fingerprint of the tags.
   261  
   262  [1]: /docs/providers/google/r/compute_instance_group_manager.html
   263  [2]: /docs/configuration/resources.html#lifecycle