github.com/nathanielks/terraform@v0.6.1-0.20170509030759-13e1a62319dc/website/source/docs/providers/google/r/compute_instance.html.markdown (about)

     1  ---
     2  layout: "google"
     3  page_title: "Google: google_compute_instance"
     4  sidebar_current: "docs-google-compute-instance"
     5  description: |-
     6    Manages a VM instance resource within GCE.
     7  ---
     8  
     9  # google\_compute\_instance
    10  
    11  Manages a VM instance resource within GCE. For more information see
    12  [the official documentation](https://cloud.google.com/compute/docs/instances)
    13  and
    14  [API](https://cloud.google.com/compute/docs/reference/latest/instances).
    15  
    16  
    17  ## Example Usage
    18  
    19  ```hcl
    20  resource "google_compute_instance" "default" {
    21    name         = "test"
    22    machine_type = "n1-standard-1"
    23    zone         = "us-central1-a"
    24  
    25    tags = ["foo", "bar"]
    26  
    27    disk {
    28      image = "debian-cloud/debian-8"
    29    }
    30  
    31    // Local SSD disk
    32    disk {
    33      type    = "local-ssd"
    34      scratch = true
    35    }
    36  
    37    network_interface {
    38      network = "default"
    39  
    40      access_config {
    41        // Ephemeral IP
    42      }
    43    }
    44  
    45    metadata {
    46      foo = "bar"
    47    }
    48  
    49    metadata_startup_script = "echo hi > /test.txt"
    50  
    51    service_account {
    52      scopes = ["userinfo-email", "compute-ro", "storage-ro"]
    53    }
    54  }
    55  ```
    56  
    57  ## Argument Reference
    58  
    59  The following arguments are supported:
    60  
    61  * `disk` - (Required) Disks to attach to the instance. This can be specified
    62      multiple times for multiple disks. Structure is documented below.
    63  
    64  * `machine_type` - (Required) The machine type to create. To create a custom
    65      machine type, value should be set as specified
    66      [here](https://cloud.google.com/compute/docs/reference/latest/instances#machineType)
    67  
    68  * `name` - (Required) A unique name for the resource, required by GCE.
    69      Changing this forces a new resource to be created.
    70  
    71  * `zone` - (Required) The zone that the machine should be created in.
    72  
    73  * `network_interface` - (Required) Networks to attach to the instance. This can
    74      be specified multiple times for multiple networks, but GCE is currently
    75      limited to just 1. Structure is documented below.
    76  
    77  - - -
    78  
    79  * `can_ip_forward` - (Optional) Whether to allow sending and receiving of
    80      packets with non-matching source or destination IPs.
    81      This defaults to false.
    82  
    83  * `description` - (Optional) A brief description of this resource.
    84  
    85  * `metadata` - (Optional) Metadata key/value pairs to make available from
    86      within the instance.
    87  
    88  * `metadata_startup_script` - (Optional) An alternative to using the
    89      startup-script metadata key, except this one forces the instance to be
    90      recreated (thus re-running the script) if it is changed. This replaces the
    91      startup-script metadata key on the created instance and thus the two
    92      mechanisms are not allowed to be used simultaneously.
    93  
    94  * `project` - (Optional) The project in which the resource belongs. If it
    95      is not provided, the provider project is used.
    96  
    97  * `scheduling` - (Optional) The scheduling strategy to use. More details about
    98      this configuration option are detailed below.
    99  
   100  * `service_account` - (Optional) Service account to attach to the instance.
   101      Structure is documented below.
   102  
   103  * `tags` - (Optional) Tags to attach to the instance.
   104  
   105  * `create_timeout` - (Optional) Configurable timeout in minutes for creating instances. Default is 4 minutes.
   106      Changing this forces a new resource to be created.
   107  
   108  ---
   109  
   110  * `network` - (DEPRECATED, Required) Networks to attach to the instance. This
   111      can be specified multiple times for multiple networks. Structure is
   112      documented below.
   113  
   114  The `disk` block supports: (Note that either disk or image is required, unless
   115  the type is "local-ssd", in which case scratch must be true).
   116  
   117  * `disk` - The name of the existing disk (such as those managed by
   118      `google_compute_disk`) to attach.
   119  
   120  * `image` - The image from which to initialize this disk. This can be
   121      one of: the image's `self_link`, `projects/{project}/global/images/{image}`,
   122      `projects/{project}/global/images/family/{family}`, `global/images/{image}`,
   123      `global/images/family/{family}`, `family/{family}`, `{project}/{family}`,
   124      `{project}/{image}`, `{family}`, or `{image}`.
   125  
   126  * `auto_delete` - (Optional) Whether or not the disk should be auto-deleted.
   127      This defaults to true. Leave true for local SSDs.
   128  
   129  * `type` - (Optional) The GCE disk type, e.g. pd-standard, pd-ssd, or local-ssd.
   130  
   131  * `scratch` - (Optional) Whether the disk is a scratch disk as opposed to a
   132      persistent disk (required for local-ssd).
   133  
   134  * `size` - (Optional) The size of the image in gigabytes. If not specified, it
   135      will inherit the size of its base image. Do not specify for local SSDs as
   136      their size is fixed.
   137  
   138  * `device_name` - (Optional) Name with which attached disk will be accessible
   139      under `/dev/disk/by-id/`
   140  
   141  * `disk_encryption_key_raw` - (Optional) A 256-bit [customer-supplied encryption key]
   142      (https://cloud.google.com/compute/docs/disks/customer-supplied-encryption),
   143      encoded in [RFC 4648 base64](https://tools.ietf.org/html/rfc4648#section-4)
   144      to encrypt this disk.
   145  
   146  The `network_interface` block supports:
   147  
   148  * `network` - (Optional) The name or self_link of the network to attach this interface to.
   149      Either `network` or `subnetwork` must be provided.
   150  
   151  *  `subnetwork` - (Optional) The name of the subnetwork to attach this interface
   152      to. The subnetwork must exist in the same region this instance will be
   153      created in. Either `network` or `subnetwork` must be provided.
   154  
   155  *  `subnetwork_project` - (Optional) The project in which the subnetwork belongs.
   156     If it is not provided, the provider project is used.
   157  
   158  * `address` - (Optional) The private IP address to assign to the instance. If
   159      empty, the address will be automatically assigned.
   160  
   161  * `access_config` - (Optional) Access configurations, i.e. IPs via which this
   162      instance can be accessed via the Internet. Omit to ensure that the instance
   163      is not accessible from the Internet (this means that ssh provisioners will
   164      not work unless you are running Terraform can send traffic to the instance's
   165      network (e.g. via tunnel or because it is running on another cloud instance
   166      on that network). This block can be repeated multiple times. Structure
   167      documented below.
   168  
   169  The `access_config` block supports:
   170  
   171  * `nat_ip` - (Optional) The IP address that will be 1:1 mapped to the instance's
   172      network ip. If not given, one will be generated.
   173  
   174  The `service_account` block supports:
   175  
   176  * `email` - (Optional) The service account e-mail address. If not given, the
   177      default Google Compute Engine service account is used.
   178  
   179  * `scopes` - (Required) A list of service scopes. Both OAuth2 URLs and gcloud
   180      short names are supported.
   181  
   182  (DEPRECATED) The `network` block supports:
   183  
   184  * `source` - (Required) The name of the network to attach this interface to.
   185  
   186  * `address` - (Optional) The IP address of a reserved IP address to assign
   187      to this interface.
   188  
   189  The `scheduling` block supports:
   190  
   191  * `preemptible` - (Optional) Is the instance preemptible.
   192  
   193  * `on_host_maintenance` - (Optional) Describes maintenance behavior for the
   194      instance. Can be MIGRATE or TERMINATE, for more info, read
   195      [here](https://cloud.google.com/compute/docs/instances/setting-instance-scheduling-options)
   196  
   197  * `automatic_restart` - (Optional) Specifies if the instance should be
   198      restarted if it was terminated by Compute Engine (not a user).
   199  
   200  ## Attributes Reference
   201  
   202  In addition to the arguments listed above, the following computed attributes are
   203  exported:
   204  
   205  * `metadata_fingerprint` - The unique fingerprint of the metadata.
   206  
   207  * `self_link` - The URI of the created resource.
   208  
   209  * `tags_fingerprint` - The unique fingerprint of the tags.
   210  
   211  * `network_interface.0.address` - The internal ip address of the instance, either manually or dynamically assigned.
   212  
   213  * `network_interface.0.access_config.0.assigned_nat_ip` - If the instance has an access config, either the given external ip (in the `nat_ip` field) or the ephemeral (generated) ip (if you didn't provide one).
   214  
   215  * `disk.0.disk_encryption_key_sha256` - The [RFC 4648 base64](https://tools.ietf.org/html/rfc4648#section-4)
   216      encoded SHA-256 hash of the [customer-supplied encryption key]
   217      (https://cloud.google.com/compute/docs/disks/customer-supplied-encryption) that protects this resource.