2014-08-26 23:50:29 +02:00
|
|
|
---
|
|
|
|
layout: "google"
|
|
|
|
page_title: "Google: google_compute_instance"
|
2015-10-23 16:10:41 +02:00
|
|
|
sidebar_current: "docs-google-compute-instance"
|
2014-10-22 05:21:56 +02:00
|
|
|
description: |-
|
|
|
|
Manages a VM instance resource within GCE.
|
2014-08-26 23:50:29 +02:00
|
|
|
---
|
|
|
|
|
|
|
|
# google\_compute\_instance
|
|
|
|
|
2016-04-10 23:34:15 +02:00
|
|
|
Manages a VM instance resource within GCE. For more information see
|
2014-11-20 18:40:17 +01:00
|
|
|
[the official documentation](https://cloud.google.com/compute/docs/instances)
|
|
|
|
and
|
|
|
|
[API](https://cloud.google.com/compute/docs/reference/latest/instances).
|
|
|
|
|
2014-08-26 23:50:29 +02:00
|
|
|
|
|
|
|
## Example Usage
|
|
|
|
|
2016-04-10 23:34:15 +02:00
|
|
|
```js
|
2014-08-26 23:50:29 +02:00
|
|
|
resource "google_compute_instance" "default" {
|
2016-04-10 23:34:15 +02:00
|
|
|
name = "test"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
|
|
|
|
tags = ["foo", "bar"]
|
|
|
|
|
|
|
|
disk {
|
|
|
|
image = "debian-7-wheezy-v20160301"
|
|
|
|
}
|
|
|
|
|
|
|
|
// Local SSD disk
|
|
|
|
disk {
|
|
|
|
type = "local-ssd"
|
|
|
|
scratch = true
|
|
|
|
}
|
|
|
|
|
|
|
|
network_interface {
|
|
|
|
network = "default"
|
|
|
|
access_config {
|
|
|
|
// Ephemeral IP
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
metadata {
|
|
|
|
foo = "bar"
|
|
|
|
}
|
|
|
|
|
|
|
|
metadata_startup_script = "echo hi > /test.txt"
|
|
|
|
|
|
|
|
service_account {
|
|
|
|
scopes = ["userinfo-email", "compute-ro", "storage-ro"]
|
|
|
|
}
|
2014-08-26 23:50:29 +02:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
## Argument Reference
|
|
|
|
|
|
|
|
The following arguments are supported:
|
|
|
|
|
2016-04-10 23:34:15 +02:00
|
|
|
* `disk` - (Required) Disks to attach to the instance. This can be specified
|
|
|
|
multiple times for multiple disks. Structure is documented below.
|
2014-08-26 23:50:29 +02:00
|
|
|
|
2016-04-10 23:34:15 +02:00
|
|
|
* `machine_type` - (Required) The machine type to create.To create a custom
|
|
|
|
machine type, value should be set as specified
|
|
|
|
[here](https://cloud.google.com/compute/docs/reference/latest/instances#machineType)
|
2014-08-26 23:50:29 +02:00
|
|
|
|
2016-04-10 23:34:15 +02:00
|
|
|
* `name` - (Required) A unique name for the resource, required by GCE.
|
|
|
|
Changing this forces a new resource to be created.
|
2014-08-26 23:50:29 +02:00
|
|
|
|
|
|
|
* `zone` - (Required) The zone that the machine should be created in.
|
|
|
|
|
2016-04-10 23:34:15 +02:00
|
|
|
- - -
|
2014-08-26 23:50:29 +02:00
|
|
|
|
2014-10-07 18:24:13 +02:00
|
|
|
* `can_ip_forward` - (Optional) Whether to allow sending and receiving of
|
|
|
|
packets with non-matching source or destination IPs.
|
|
|
|
This defaults to false.
|
|
|
|
|
2016-04-10 23:34:15 +02:00
|
|
|
* `description` - (Optional) A brief description of this resource.
|
|
|
|
|
2014-08-26 23:50:29 +02:00
|
|
|
* `metadata` - (Optional) Metadata key/value pairs to make available from
|
|
|
|
within the instance.
|
|
|
|
|
2015-07-02 03:24:34 +02:00
|
|
|
* `metadata_startup_script` - (Optional) An alternative to using the
|
2016-04-10 23:34:15 +02:00
|
|
|
startup-script metadata key, except this one forces the instance to be
|
|
|
|
recreated (thus re-running the script) if it is changed. This replaces the
|
|
|
|
startup-script metadata key on the created instance and thus the two
|
|
|
|
mechanisms are not allowed to be used simultaneously.
|
2015-07-02 03:24:34 +02:00
|
|
|
|
2016-04-10 23:34:15 +02:00
|
|
|
* `network_interface` - (Required) Networks to attach to the instance. This can
|
|
|
|
be specified multiple times for multiple networks, but GCE is currently
|
|
|
|
limited to just 1. Structure is documented below.
|
2015-02-06 09:21:22 +01:00
|
|
|
|
2016-04-10 23:34:15 +02:00
|
|
|
* `network` - (DEPRECATED, Required) Networks to attach to the instance. This
|
|
|
|
can be specified multiple times for multiple networks. Structure is
|
|
|
|
documented below.
|
|
|
|
|
|
|
|
* `project` - (Optional) The project in which the resource belongs. If it
|
|
|
|
is not provided, the provider project is used.
|
|
|
|
|
|
|
|
* `scheduling` - (Optional) The scheduling strategy to use. More details about
|
|
|
|
this configuration option are detailed below.
|
2014-08-26 23:50:29 +02:00
|
|
|
|
2014-10-07 10:16:50 +02:00
|
|
|
* `service_account` - (Optional) Service account to attach to the instance.
|
|
|
|
|
2014-08-26 23:50:29 +02:00
|
|
|
* `tags` - (Optional) Tags to attach to the instance.
|
|
|
|
|
2015-05-12 03:40:37 +02:00
|
|
|
The `disk` block supports: (Note that either disk or image is required, unless
|
|
|
|
the type is "local-ssd", in which case scratch must be true).
|
2014-08-26 23:50:29 +02:00
|
|
|
|
2015-05-12 03:40:37 +02:00
|
|
|
* `disk` - The name of the existing disk (such as those managed by
|
2016-04-10 23:34:15 +02:00
|
|
|
`google_compute_disk`) to attach.
|
2014-08-26 23:50:29 +02:00
|
|
|
|
2015-05-12 03:40:37 +02:00
|
|
|
* `image` - The image from which to initialize this
|
2016-04-10 23:34:15 +02:00
|
|
|
disk. Either the full URL, a contraction of the form "project/name", or
|
|
|
|
just a name (in which case the current project is used).
|
2014-08-26 23:50:29 +02:00
|
|
|
|
2014-09-08 01:10:56 +02:00
|
|
|
* `auto_delete` - (Optional) Whether or not the disk should be auto-deleted.
|
2016-04-10 23:34:15 +02:00
|
|
|
This defaults to true. Leave true for local SSDs.
|
2015-05-12 03:40:37 +02:00
|
|
|
|
|
|
|
* `type` - (Optional) The GCE disk type, e.g. pd-standard, pd-ssd, or local-ssd.
|
2014-09-08 01:10:56 +02:00
|
|
|
|
2015-05-12 03:40:37 +02:00
|
|
|
* `scratch` - (Optional) Whether the disk is a scratch disk as opposed to a
|
|
|
|
persistent disk (required for local-ssd).
|
2014-10-07 06:59:09 +02:00
|
|
|
|
2015-05-12 03:40:37 +02:00
|
|
|
* `size` - (Optional) The size of the image in gigabytes. If not specified, it
|
2016-04-10 23:34:15 +02:00
|
|
|
will inherit the size of its base image. Do not specify for local SSDs as
|
2015-05-12 03:40:37 +02:00
|
|
|
their size is fixed.
|
2015-03-24 17:45:20 +01:00
|
|
|
|
2015-04-08 13:41:47 +02:00
|
|
|
* `device_name` - (Optional) Name with which attached disk will be accessible
|
|
|
|
under `/dev/disk/by-id/`
|
|
|
|
|
2015-02-06 09:21:22 +01:00
|
|
|
The `network_interface` block supports:
|
|
|
|
|
2016-04-10 23:34:15 +02:00
|
|
|
* `network` - (Optional) The name of the network to attach this interface to.
|
|
|
|
Either `network` or `subnetwork` must be provided.
|
2016-03-31 12:37:17 +02:00
|
|
|
|
2016-04-10 23:34:15 +02:00
|
|
|
* `subnetwork` - (Optional) the name of the subnetwork to attach this interface
|
|
|
|
to. The subnetwork must exist in the same region this instance will be
|
|
|
|
created in. Either `network` or `subnetwork` must be provided.
|
2015-02-06 09:21:22 +01:00
|
|
|
|
2016-04-10 23:34:15 +02:00
|
|
|
* `access_config` - (Optional) Access configurations, i.e. IPs via which this
|
|
|
|
instance can be accessed via the Internet. Omit to ensure that the instance
|
|
|
|
is not accessible from the Internet (this means that ssh provisioners will
|
|
|
|
not work unless you are running Terraform can send traffic tothe instance's
|
|
|
|
network (e.g. via tunnel or because it is running on another cloud instance
|
|
|
|
on that network). This block can be repeated multiple times. Structure
|
|
|
|
documented below.
|
2015-02-06 09:21:22 +01:00
|
|
|
|
|
|
|
The `access_config` block supports:
|
|
|
|
|
2016-04-10 23:34:15 +02:00
|
|
|
* `nat_ip` - (Optional) The IP address that will be 1:1 mapped to the instance's
|
|
|
|
network ip. If not given, one will be generated.
|
2015-02-06 09:21:22 +01:00
|
|
|
|
2015-12-11 17:41:02 +01:00
|
|
|
* `assigned_nat_ip` - (Optional) The IP address that is assigned to the
|
2016-04-10 23:34:15 +02:00
|
|
|
instance. If `nat_ip` is filled, it will appear here. If `nat_ip` is left
|
|
|
|
blank, the ephemeral assigned IP will appear here.
|
2015-12-11 17:41:02 +01:00
|
|
|
|
2015-02-06 09:21:22 +01:00
|
|
|
(DEPRECATED) The `network` block supports:
|
2014-08-26 23:50:29 +02:00
|
|
|
|
|
|
|
* `source` - (Required) The name of the network to attach this interface to.
|
|
|
|
|
|
|
|
* `address` - (Optional) The IP address of a reserved IP address to assign
|
2016-04-10 23:34:15 +02:00
|
|
|
to this interface.
|
2014-08-26 23:50:29 +02:00
|
|
|
|
2014-10-07 10:16:50 +02:00
|
|
|
The `service_account` block supports:
|
|
|
|
|
2015-01-14 18:28:25 +01:00
|
|
|
* `scopes` - (Required) A list of service scopes. Both OAuth2 URLs and gcloud
|
2014-10-07 10:16:50 +02:00
|
|
|
short names are supported.
|
|
|
|
|
2015-10-26 21:16:06 +01:00
|
|
|
The `scheduling` block supports:
|
|
|
|
|
|
|
|
* `preemptible` - (Optional) Is the instance preemptible.
|
|
|
|
|
2016-04-10 23:34:15 +02:00
|
|
|
* `on_host_maintenance` - (Optional) Describes maintenance behavior for the
|
|
|
|
instance. Can be MIGRATE or TERMINATE, for more info, read
|
2015-10-26 21:16:06 +01:00
|
|
|
[here](https://cloud.google.com/compute/docs/instances/setting-instance-scheduling-options)
|
|
|
|
|
|
|
|
* `automatic_restart` - (Optional) Specifies if the instance should be
|
|
|
|
restarted if it was terminated by Compute Engine (not a user).
|
|
|
|
|
2014-08-26 23:50:29 +02:00
|
|
|
## Attributes Reference
|
|
|
|
|
2016-04-10 23:34:15 +02:00
|
|
|
In addition to the arguments listed above, the following computed attributes are
|
|
|
|
exported:
|
|
|
|
|
|
|
|
* `metadata_fingerprint` - The unique fingerprint of the metadata.
|
|
|
|
|
|
|
|
* `self_link` - The URI of the created resource.
|
2014-08-26 23:50:29 +02:00
|
|
|
|
2016-04-10 23:34:15 +02:00
|
|
|
* `tags_fingerprint` - The unique fingerprint of the tags.
|