github.com/turtlemonvh/terraform@v0.6.9-0.20151204001754-8e40b6b855e8/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  ```
    20  resource "google_compute_instance" "default" {
    21  	name = "test"
    22  	machine_type = "n1-standard-1"
    23  	zone = "us-central1-a"
    24  	tags = ["foo", "bar"]
    25  
    26  	disk {
    27  		image = "debian-7-wheezy-v20140814"
    28  	}
    29  
    30  	// Local SSD disk
    31  	disk {
    32  		type = "local-ssd"
    33  		scratch = true
    34  	}
    35  
    36  	network_interface {
    37  		network = "default"
    38          access_config {
    39              // Ephemeral IP
    40          }
    41  	}
    42  
    43  	metadata {
    44  		foo = "bar"
    45  	}
    46  
    47      metadata_startup_script = "echo hi > /test.txt"
    48  
    49  	service_account {
    50  		scopes = ["userinfo-email", "compute-ro", "storage-ro"]
    51  	}
    52  }
    53  ```
    54  
    55  ## Argument Reference
    56  
    57  The following arguments are supported:
    58  
    59  * `name` - (Required) A unique name for the resource, required by GCE.
    60      Changing this forces a new resource to be created.
    61  
    62  * `description` - (Optional) A brief description of this resource.
    63  
    64  * `machine_type` - (Required) The machine type to create.
    65  
    66  * `zone` - (Required) The zone that the machine should be created in.
    67  
    68  * `disk` - (Required) Disks to attach to the instance. This can be specified
    69      multiple times for multiple disks. Structure is documented below.
    70  
    71  * `can_ip_forward` - (Optional) Whether to allow sending and receiving of
    72      packets with non-matching source or destination IPs.
    73      This defaults to false.
    74  
    75  * `metadata` - (Optional) Metadata key/value pairs to make available from
    76      within the instance.
    77  
    78  * `metadata_startup_script` - (Optional) An alternative to using the
    79    startup-script metadata key, except this one forces the instance to be
    80    recreated (thus re-running the script) if it is changed.  This replaces the
    81    startup-script metadata key on the created instance and thus the two mechanisms
    82    are not allowed to be used simultaneously.
    83  
    84  * `network_interface` - (Required) Networks to attach to the instance. This can be
    85      specified multiple times for multiple networks, but GCE is currently limited
    86      to just 1. Structure is documented below.
    87  
    88  * `network` - (DEPRECATED, Required) Networks to attach to the instance. This can be
    89      specified multiple times for multiple networks. Structure is documented
    90      below.
    91  
    92  * `service_account` - (Optional) Service account to attach to the instance.
    93  
    94  * `tags` - (Optional) Tags to attach to the instance.
    95  
    96  The `disk` block supports: (Note that either disk or image is required, unless
    97  the type is "local-ssd", in which case scratch must be true).
    98  
    99  * `disk` - The name of the existing disk (such as those managed by
   100    `google_compute_disk`) to attach.
   101  
   102  * `image` - The image from which to initialize this
   103      disk.  Either the full URL, a contraction of the form "project/name", or just
   104      a name (in which case the current project is used).
   105  
   106  * `auto_delete` - (Optional) Whether or not the disk should be auto-deleted.
   107      This defaults to true.  Leave true for local SSDs.
   108  
   109  * `type` - (Optional) The GCE disk type, e.g. pd-standard, pd-ssd, or local-ssd.
   110  
   111  * `scratch` - (Optional) Whether the disk is a scratch disk as opposed to a
   112      persistent disk (required for local-ssd).
   113  
   114  * `size` - (Optional) The size of the image in gigabytes. If not specified, it
   115      will inherit the size of its base image.  Do not specify for local SSDs as
   116      their size is fixed.
   117  
   118  * `device_name` - (Optional) Name with which attached disk will be accessible
   119      under `/dev/disk/by-id/`
   120  
   121  The `network_interface` block supports:
   122  
   123  * `network` - (Required) The name of the network to attach this interface to.
   124  
   125  * `access_config` - (Optional) Access configurations, i.e. IPs via which this instance can be
   126    accessed via the Internet.  Omit to ensure that the instance is not accessible from the Internet
   127  (this means that ssh provisioners will not work unless you are running Terraform can send traffic to
   128  the instance's network (e.g. via tunnel or because it is running on another cloud instance on that
   129  network).  This block can be repeated multiple times.  Structure documented below.
   130  
   131  The `access_config` block supports:
   132  
   133  * `nat_ip` - (Optional) The IP address that will be 1:1 mapped to the instance's network ip.  If not
   134    given, one will be generated.
   135  
   136  (DEPRECATED) The `network` block supports:
   137  
   138  * `source` - (Required) The name of the network to attach this interface to.
   139  
   140  * `address` - (Optional) The IP address of a reserved IP address to assign
   141       to this interface.
   142  
   143  The `service_account` block supports:
   144  
   145  * `scopes` - (Required) A list of service scopes. Both OAuth2 URLs and gcloud
   146      short names are supported.
   147  
   148  The `scheduling` block supports:
   149  
   150  * `preemptible` - (Optional) Is the instance preemptible.
   151  
   152  * `on_host_maintenance` - (Optional) Describes maintenance behavior for 
   153      the instance. Can be MIGRATE or TERMINATE, for more info, read
   154      [here](https://cloud.google.com/compute/docs/instances/setting-instance-scheduling-options)
   155  
   156  * `automatic_restart` - (Optional) Specifies if the instance should be
   157      restarted if it was terminated by Compute Engine (not a user).
   158  
   159  ## Attributes Reference
   160  
   161  The following attributes are exported:
   162  
   163  * `name` - The name of the resource.
   164  * `machine_type` - The type of machine.
   165  * `zone` - The zone the machine lives in.