github.com/ves/terraform@v0.8.0-beta2/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  * `network_interface` - (Required) Networks to attach to instances created from
   140      this template. This can be specified multiple times for multiple networks.
   141      Structure is documented below.
   142  
   143  * `project` - (Optional) The project in which the resource belongs. If it
   144      is not provided, the provider project is used.
   145  
   146  * `region` - (Optional) An instance template is a global resource that is not
   147      bound to a zone or a region. However, you can still specify some regional
   148      resources in an instance template, which restricts the template to the
   149      region where that resource resides. For example, a custom `subnetwork`
   150      resource is tied to a specific region. Defaults to the region of the
   151      Provider if no value is given.
   152  
   153  * `scheduling` - (Optional) The scheduling strategy to use. More details about
   154      this configuration option are detailed below.
   155  
   156  * `service_account` - (Optional) Service account to attach to the instance. Structure is documented below.
   157  
   158  * `tags` - (Optional) Tags to attach to the instance.
   159  
   160  The `disk` block supports:
   161  
   162  * `auto_delete` - (Optional) Whether or not the disk should be auto-deleted.
   163      This defaults to true.
   164  
   165  * `boot` - (Optional) Indicates that this is a boot disk.
   166  
   167  * `device_name` - (Optional) A unique device name that is reflected into the
   168      /dev/  tree of a Linux operating system running within the instance. If not
   169      specified, the server chooses a default device name to apply to this disk.
   170  
   171  * `disk_name` - (Optional) Name of the disk. When not provided, this defaults
   172      to the name of the instance.
   173  
   174  * `source_image` - (Required if source not set) The name of the image to base
   175      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).
   176  
   177  * `interface` - (Optional) Specifies the disk interface to use for attaching
   178      this disk.
   179  
   180  * `mode` - (Optional) The mode in which to attach this disk, either READ_WRITE
   181      or READ_ONLY. If you are attaching or creating a boot disk, this must
   182      read-write mode.
   183  
   184  * `source` - (Required if source_image not set) The name of the disk (such as
   185      those managed by `google_compute_disk`) to attach.
   186  
   187  * `disk_type` - (Optional) The GCE disk type. Can be either `"pd-ssd"`,
   188      `"local-ssd"`, or `"pd-standard"`.
   189  
   190  * `disk_size_gb` - (Optional) The size of the image in gigabytes. If not
   191      specified, it will inherit the size of its base image.
   192  
   193  * `type` - (Optional) The type of GCE disk, can be either `"SCRATCH"` or
   194      `"PERSISTENT"`.
   195  
   196  The `network_interface` block supports:
   197  
   198  * `network` - (Optional) The name or self_link of the network to attach this interface to.
   199      Use `network` attribute for Legacy or Auto subnetted networks and
   200      `subnetwork` for custom subnetted networks.
   201  
   202  * `subnetwork` - (Optional) the name of the subnetwork to attach this interface
   203      to. The subnetwork must exist in the same `region` this instance will be
   204      created in. Either `network` or `subnetwork` must be provided.
   205  
   206  * `access_config` - (Optional) Access configurations, i.e. IPs via which this
   207      instance can be accessed via the Internet. Omit to ensure that the instance
   208      is not accessible from the Internet (this means that ssh provisioners will
   209      not work unless you are running Terraform can send traffic to the instance's
   210      network (e.g. via tunnel or because it is running on another cloud instance
   211      on that network). This block can be repeated multiple times. Structure documented below.
   212  
   213  The `access_config` block supports:
   214  
   215  * `nat_ip` - (Optional) The IP address that will be 1:1 mapped to the instance's
   216      network ip. If not given, one will be generated.
   217  
   218  The `service_account` block supports:
   219  
   220  * `email` - (Optional) The service account e-mail address. If not given, the
   221      default Google Compute Engine service account is used.
   222  
   223  * `scopes` - (Required) A list of service scopes. Both OAuth2 URLs and gcloud
   224      short names are supported.
   225  
   226  The `scheduling` block supports:
   227  
   228  * `automatic_restart` - (Optional) Specifies whether the instance should be
   229      automatically restarted if it is terminated by Compute Engine (not
   230      terminated by a user). This defaults to true.
   231  
   232  * `on_host_maintenance` - (Optional) Defines the maintenance behavior for this
   233      instance.
   234  
   235  * `preemptible` - (Optional) Allows instance to be preempted. This defaults to
   236      false. Read more on this
   237      [here](https://cloud.google.com/compute/docs/instances/preemptible).
   238  
   239  ## Attributes Reference
   240  
   241  In addition to the arguments listed above, the following computed attributes are
   242  exported:
   243  
   244  * `metadata_fingerprint` - The unique fingerprint of the metadata.
   245  
   246  * `self_link` - The URI of the created resource.
   247  
   248  * `tags_fingerprint` - The unique fingerprint of the tags.
   249  
   250  [1]: /docs/providers/google/r/compute_instance_group_manager.html
   251  [2]: /docs/configuration/resources.html#lifecycle