github.com/xsb/terraform@v0.6.13-0.20160314145438-fe415c2f09d7/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.To create a custom machine type, value should be 65 set as specified [here](https://cloud.google.com/compute/docs/reference/latest/instances#machineType) 66 67 * `zone` - (Required) The zone that the machine should be created in. 68 69 * `disk` - (Required) Disks to attach to the instance. This can be specified 70 multiple times for multiple disks. Structure is documented below. 71 72 * `can_ip_forward` - (Optional) Whether to allow sending and receiving of 73 packets with non-matching source or destination IPs. 74 This defaults to false. 75 76 * `metadata` - (Optional) Metadata key/value pairs to make available from 77 within the instance. 78 79 * `metadata_startup_script` - (Optional) An alternative to using the 80 startup-script metadata key, except this one forces the instance to be 81 recreated (thus re-running the script) if it is changed. This replaces the 82 startup-script metadata key on the created instance and thus the two mechanisms 83 are not allowed to be used simultaneously. 84 85 * `network_interface` - (Required) Networks to attach to the instance. This can be 86 specified multiple times for multiple networks, but GCE is currently limited 87 to just 1. Structure is documented below. 88 89 * `network` - (DEPRECATED, Required) Networks to attach to the instance. This can be 90 specified multiple times for multiple networks. Structure is documented 91 below. 92 93 * `service_account` - (Optional) Service account to attach to the instance. 94 95 * `tags` - (Optional) Tags to attach to the instance. 96 97 The `disk` block supports: (Note that either disk or image is required, unless 98 the type is "local-ssd", in which case scratch must be true). 99 100 * `disk` - The name of the existing disk (such as those managed by 101 `google_compute_disk`) to attach. 102 103 * `image` - The image from which to initialize this 104 disk. Either the full URL, a contraction of the form "project/name", or just 105 a name (in which case the current project is used). 106 107 * `auto_delete` - (Optional) Whether or not the disk should be auto-deleted. 108 This defaults to true. Leave true for local SSDs. 109 110 * `type` - (Optional) The GCE disk type, e.g. pd-standard, pd-ssd, or local-ssd. 111 112 * `scratch` - (Optional) Whether the disk is a scratch disk as opposed to a 113 persistent disk (required for local-ssd). 114 115 * `size` - (Optional) The size of the image in gigabytes. If not specified, it 116 will inherit the size of its base image. Do not specify for local SSDs as 117 their size is fixed. 118 119 * `device_name` - (Optional) Name with which attached disk will be accessible 120 under `/dev/disk/by-id/` 121 122 The `network_interface` block supports: 123 124 * `network` - (Optional) The name of the network to attach this interface to. Either 125 `network` or `subnetwork` must be provided. 126 127 * `subnetwork` - (Optional) the name of the subnetwork to attach this interface to. The subnetwork 128 must exist in the same region this instance will be created in. Either `network` 129 or `subnetwork` must be provided. 130 131 * `access_config` - (Optional) Access configurations, i.e. IPs via which this instance can be 132 accessed via the Internet. Omit to ensure that the instance is not accessible from the Internet 133 (this means that ssh provisioners will not work unless you are running Terraform can send traffic to 134 the instance's network (e.g. via tunnel or because it is running on another cloud instance on that 135 network). This block can be repeated multiple times. Structure documented below. 136 137 The `access_config` block supports: 138 139 * `nat_ip` - (Optional) The IP address that will be 1:1 mapped to the instance's network ip. If not 140 given, one will be generated. 141 142 * `assigned_nat_ip` - (Optional) The IP address that is assigned to the 143 instance. If `nat_ip` is filled, it will appear here. If `nat_ip` is left 144 blank, the ephemeral assigned IP will appear here. 145 146 (DEPRECATED) The `network` block supports: 147 148 * `source` - (Required) The name of the network to attach this interface to. 149 150 * `address` - (Optional) The IP address of a reserved IP address to assign 151 to this interface. 152 153 The `service_account` block supports: 154 155 * `scopes` - (Required) A list of service scopes. Both OAuth2 URLs and gcloud 156 short names are supported. 157 158 The `scheduling` block supports: 159 160 * `preemptible` - (Optional) Is the instance preemptible. 161 162 * `on_host_maintenance` - (Optional) Describes maintenance behavior for 163 the instance. Can be MIGRATE or TERMINATE, for more info, read 164 [here](https://cloud.google.com/compute/docs/instances/setting-instance-scheduling-options) 165 166 * `automatic_restart` - (Optional) Specifies if the instance should be 167 restarted if it was terminated by Compute Engine (not a user). 168 169 ## Attributes Reference 170 171 The following attributes are exported: 172 173 * `name` - The name of the resource. 174 * `machine_type` - The type of machine. 175 * `zone` - The zone the machine lives in.