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