terraform/website/source/docs/providers/google/r/compute_instance.html.markdown

147 lines
4.5 KiB
Markdown
Raw Normal View History

2014-08-26 23:50:29 +02:00
---
layout: "google"
page_title: "Google: google_compute_instance"
sidebar_current: "docs-google-resource-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
Manages a VM instance resource within GCE. For more information see
[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
```
resource "google_compute_instance" "default" {
name = "test"
machine_type = "n1-standard-1"
zone = "us-central1-a"
tags = ["foo", "bar"]
disk {
image = "debian-7-wheezy-v20140814"
}
2015-05-12 03:40:37 +02:00
// Local SSD disk
disk {
type = "local-ssd"
scratch = true
}
network_interface {
network = "default"
access_config {
// Ephemeral IP
}
2014-08-26 23:50:29 +02:00
}
metadata {
foo = "bar"
}
service_account {
scopes = ["userinfo-email", "compute-ro", "storage-ro"]
}
2014-08-26 23:50:29 +02:00
}
```
## Argument Reference
The following arguments are supported:
* `name` - (Required) A unique name for the resource, required by GCE.
Changing this forces a new resource to be created.
* `description` - (Optional) A brief description of this resource.
* `machine_type` - (Required) The machine type to create.
* `zone` - (Required) The zone that the machine should be created in.
* `disk` - (Required) Disks to attach to the instance. This can be specified
multiple times for multiple disks. Structure is documented below.
* `can_ip_forward` - (Optional) Whether to allow sending and receiving of
packets with non-matching source or destination IPs.
This defaults to false.
2014-08-26 23:50:29 +02:00
* `metadata` - (Optional) Metadata key/value pairs to make available from
within the instance.
* `network_interface` - (Required) Networks to attach to the instance. This can be
specified multiple times for multiple networks. Structure is documented
below.
* `network` - (DEPRECATED, Required) Networks to attach to the instance. This can be
2014-08-26 23:50:29 +02:00
specified multiple times for multiple networks. Structure is documented
below.
* `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
`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
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.
2015-05-12 03:40:37 +02:00
This defaults to true. Leave true for local SSDs.
* `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).
2015-05-12 03:40:37 +02:00
* `size` - (Optional) The size of the image in gigabytes. If not specified, it
will inherit the size of its base image. Do not specify for local SSDs as
their size is fixed.
* `device_name` - (Optional) Name with which attached disk will be accessible
under `/dev/disk/by-id/`
The `network_interface` block supports:
* `network` - (Required) The name of the network to attach this interface to.
* `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 to
the 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.
The `access_config` block supports:
* `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.
(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
to this interface.
The `service_account` block supports:
* `scopes` - (Required) A list of service scopes. Both OAuth2 URLs and gcloud
short names are supported.
2014-08-26 23:50:29 +02:00
## Attributes Reference
The following attributes are exported:
* `name` - The name of the resource.
* `machine_type` - The type of machine.
* `zone` - The zone the machine lives in.