github.com/mkuzmin/terraform@v0.3.7-0.20161118171027-ec4c00ff92a9/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  ```js
    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      access_config {
    40        // Ephemeral IP
    41      }
    42    }
    43  
    44    metadata {
    45      foo = "bar"
    46    }
    47  
    48    metadata_startup_script = "echo hi > /test.txt"
    49  
    50    service_account {
    51      scopes = ["userinfo-email", "compute-ro", "storage-ro"]
    52    }
    53  }
    54  ```
    55  
    56  ## Argument Reference
    57  
    58  The following arguments are supported:
    59  
    60  * `disk` - (Required) Disks to attach to the instance. This can be specified
    61      multiple times for multiple disks. Structure is documented below.
    62  
    63  * `machine_type` - (Required) The machine type to create. To create a custom
    64      machine type, value should be set as specified
    65      [here](https://cloud.google.com/compute/docs/reference/latest/instances#machineType)
    66  
    67  * `name` - (Required) A unique name for the resource, required by GCE.
    68      Changing this forces a new resource to be created.
    69  
    70  * `zone` - (Required) The zone that the machine should be created in.
    71  
    72  - - -
    73  
    74  * `can_ip_forward` - (Optional) Whether to allow sending and receiving of
    75      packets with non-matching source or destination IPs.
    76      This defaults to false.
    77  
    78  * `description` - (Optional) A brief description of this resource.
    79  
    80  * `metadata` - (Optional) Metadata key/value pairs to make available from
    81      within the instance.
    82  
    83  * `metadata_startup_script` - (Optional) An alternative to using the
    84      startup-script metadata key, except this one forces the instance to be
    85      recreated (thus re-running the script) if it is changed. This replaces the
    86      startup-script metadata key on the created instance and thus the two
    87      mechanisms are not allowed to be used simultaneously.
    88  
    89  * `network_interface` - (Required) Networks to attach to the instance. This can
    90      be specified multiple times for multiple networks, but GCE is currently
    91      limited to just 1. Structure is documented below.
    92  
    93  * `network` - (DEPRECATED, Required) Networks to attach to the instance. This
    94      can be specified multiple times for multiple networks. Structure is
    95      documented below.
    96  
    97  * `project` - (Optional) The project in which the resource belongs. If it
    98      is not provided, the provider project is used.
    99  
   100  * `scheduling` - (Optional) The scheduling strategy to use. More details about
   101      this configuration option are detailed below.
   102  
   103  * `service_account` - (Optional) Service account to attach to the instance.
   104      Structure is documented below.
   105  
   106  * `tags` - (Optional) Tags to attach to the instance.
   107  
   108  * `create_timeout` - (Optional) Configurable timeout in minutes for creating instances. Default is 4 minutes.
   109      Changing this forces a new resource to be created.
   110  
   111  The `disk` block supports: (Note that either disk or image is required, unless
   112  the type is "local-ssd", in which case scratch must be true).
   113  
   114  * `disk` - The name of the existing disk (such as those managed by
   115      `google_compute_disk`) to attach.
   116  
   117  * `image` - The image from which to initialize this
   118      disk. Either the full URL, a contraction of the form "project/name", the
   119      name of a Google-supported
   120      [image family](https://cloud.google.com/compute/docs/images#image_families),
   121      or simple the name of an image or image family (in which case the current
   122      project is used).
   123  
   124  * `auto_delete` - (Optional) Whether or not the disk should be auto-deleted.
   125      This defaults to true. Leave true for local SSDs.
   126  
   127  * `type` - (Optional) The GCE disk type, e.g. pd-standard, pd-ssd, or local-ssd.
   128  
   129  * `scratch` - (Optional) Whether the disk is a scratch disk as opposed to a
   130      persistent disk (required for local-ssd).
   131  
   132  * `size` - (Optional) The size of the image in gigabytes. If not specified, it
   133      will inherit the size of its base image. Do not specify for local SSDs as
   134      their size is fixed.
   135  
   136  * `device_name` - (Optional) Name with which attached disk will be accessible
   137      under `/dev/disk/by-id/`
   138  
   139  The `network_interface` block supports:
   140  
   141  * `network` - (Optional) The name or self_link of the network to attach this interface to.
   142      Either `network` or `subnetwork` must be provided.
   143  
   144  *  `subnetwork` - (Optional) the name of the subnetwork to attach this interface
   145      to. The subnetwork must exist in the same region this instance will be
   146      created in. Either `network` or `subnetwork` must be provided.
   147  
   148  * `address` - (Optional) The private IP address to assign to the instance. If
   149      empty, the address will be automatically assigned.
   150  
   151  * `access_config` - (Optional) Access configurations, i.e. IPs via which this
   152      instance can be accessed via the Internet. Omit to ensure that the instance
   153      is not accessible from the Internet (this means that ssh provisioners will
   154      not work unless you are running Terraform can send traffic to the instance's
   155      network (e.g. via tunnel or because it is running on another cloud instance
   156      on that network). This block can be repeated multiple times. Structure
   157      documented below.
   158  
   159  The `access_config` block supports:
   160  
   161  * `nat_ip` - (Optional) The IP address that will be 1:1 mapped to the instance's
   162      network ip. If not given, one will be generated.
   163  
   164  The `service_account` block supports:
   165  
   166  * `email` - (Optional) The service account e-mail address. If not given, the
   167      default Google Compute Engine service account is used.
   168  
   169  * `scopes` - (Required) A list of service scopes. Both OAuth2 URLs and gcloud
   170      short names are supported.
   171  
   172  (DEPRECATED) The `network` block supports:
   173  
   174  * `source` - (Required) The name of the network to attach this interface to.
   175  
   176  * `address` - (Optional) The IP address of a reserved IP address to assign
   177      to this interface.
   178  
   179  The `scheduling` block supports:
   180  
   181  * `preemptible` - (Optional) Is the instance preemptible.
   182  
   183  * `on_host_maintenance` - (Optional) Describes maintenance behavior for the
   184      instance. Can be MIGRATE or TERMINATE, for more info, read
   185      [here](https://cloud.google.com/compute/docs/instances/setting-instance-scheduling-options)
   186  
   187  * `automatic_restart` - (Optional) Specifies if the instance should be
   188      restarted if it was terminated by Compute Engine (not a user).
   189  
   190  ## Attributes Reference
   191  
   192  In addition to the arguments listed above, the following computed attributes are
   193  exported:
   194  
   195  * `metadata_fingerprint` - The unique fingerprint of the metadata.
   196  
   197  * `self_link` - The URI of the created resource.
   198  
   199  * `tags_fingerprint` - The unique fingerprint of the tags.
   200  
   201  * `network_interface.0.address` - The internal ip address of the instance, either manually or dynamically assigned.
   202  
   203  * `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).