2016-08-12 02:35:33 +00:00
|
|
|
---
|
|
|
|
layout: "google"
|
|
|
|
page_title: "Google: google_compute_image"
|
|
|
|
sidebar_current: "docs-google-compute-image"
|
|
|
|
description: |-
|
|
|
|
Creates a bootable VM image for Google Compute Engine from an existing tarball.
|
|
|
|
---
|
|
|
|
|
|
|
|
# google\_compute\_image
|
|
|
|
|
|
|
|
Creates a bootable VM image resource for Google Compute Engine from an existing
|
|
|
|
tarball. For more information see [the official documentation](https://cloud.google.com/compute/docs/images) and
|
|
|
|
[API](https://cloud.google.com/compute/docs/reference/latest/images).
|
|
|
|
|
|
|
|
|
|
|
|
## Example Usage
|
|
|
|
|
2017-04-17 10:17:54 +00:00
|
|
|
```hcl
|
2016-08-12 02:35:33 +00:00
|
|
|
resource "google_compute_image" "bootable-image" {
|
2017-02-18 22:48:50 +00:00
|
|
|
name = "my-custom-image"
|
|
|
|
|
2016-08-12 02:35:33 +00:00
|
|
|
raw_disk {
|
|
|
|
source = "https://storage.googleapis.com/my-bucket/my-disk-image-tarball.tar.gz"
|
|
|
|
}
|
2018-06-28 16:49:34 +00:00
|
|
|
|
|
|
|
licenses = [
|
|
|
|
"https://www.googleapis.com/compute/v1/projects/vm-options/global/licenses/enable-vmx",
|
|
|
|
]
|
2016-08-12 02:35:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_instance" "vm" {
|
|
|
|
name = "vm-from-custom-image"
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
zone = "us-east1-c"
|
|
|
|
|
2017-09-29 23:04:52 +00:00
|
|
|
boot_disk {
|
|
|
|
initialize_params {
|
|
|
|
image = "${google_compute_image.bootable-image.self_link}"
|
|
|
|
}
|
2016-08-12 02:35:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
network_interface {
|
2017-02-18 22:48:50 +00:00
|
|
|
network = "default"
|
2016-08-12 02:35:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
## Argument Reference
|
|
|
|
|
2016-11-01 10:32:47 +00:00
|
|
|
The following arguments are supported: (Note that one of either source_disk or
|
|
|
|
raw_disk is required)
|
2016-08-12 02:35:33 +00:00
|
|
|
|
|
|
|
* `name` - (Required) A unique name for the resource, required by GCE.
|
|
|
|
Changing this forces a new resource to be created.
|
|
|
|
|
2018-02-02 18:56:18 +00:00
|
|
|
- - -
|
|
|
|
|
|
|
|
* `description` - (Optional) The description of the image to be created
|
|
|
|
|
|
|
|
* `family` - (Optional) The name of the image family to which this image belongs.
|
|
|
|
|
|
|
|
* `labels` - (Optional) A set of key/value label pairs to assign to the image.
|
|
|
|
|
|
|
|
* `source_disk` - (Optional) The URL of a disk that will be used as the source of the
|
2016-11-01 10:32:47 +00:00
|
|
|
image. Changing this forces a new resource to be created.
|
|
|
|
|
2018-03-12 20:59:47 +00:00
|
|
|
* `project` - (Optional) The ID of the project in which the resource belongs. If it
|
2018-02-02 18:56:18 +00:00
|
|
|
is not provided, the provider project is used.
|
|
|
|
|
|
|
|
* `raw_disk` - (Optional) The raw disk that will be used as the source of the image.
|
2016-11-01 10:32:47 +00:00
|
|
|
Changing this forces a new resource to be created. Structure is documented
|
|
|
|
below.
|
2016-08-12 02:35:33 +00:00
|
|
|
|
2018-06-28 16:49:34 +00:00
|
|
|
* `licenses` - (Optional) A list of license URIs to apply to this image. Changing this
|
|
|
|
forces a new resource to be created.
|
|
|
|
|
2016-08-12 02:35:33 +00:00
|
|
|
The `raw_disk` block supports:
|
|
|
|
|
|
|
|
* `source` - (Required) The full Google Cloud Storage URL where the disk
|
|
|
|
image is stored.
|
|
|
|
|
|
|
|
* `sha1` - (Optional) SHA1 checksum of the source tarball that will be used
|
|
|
|
to verify the source before creating the image.
|
|
|
|
|
|
|
|
* `container_type` - (Optional) The format used to encode and transmit the
|
|
|
|
block device. TAR is the only supported type and is the default.
|
|
|
|
|
|
|
|
## Attributes Reference
|
|
|
|
|
|
|
|
In addition to the arguments listed above, the following computed attributes are
|
|
|
|
exported:
|
|
|
|
|
|
|
|
* `self_link` - The URI of the created resource.
|
2017-07-14 20:32:25 +00:00
|
|
|
|
2017-08-18 20:34:11 +00:00
|
|
|
* `label_fingerprint` - The fingerprint of the assigned labels.
|
|
|
|
|
2018-02-02 18:56:18 +00:00
|
|
|
## Timeouts
|
|
|
|
|
|
|
|
`google_compute_image` provides the following
|
|
|
|
[Timeouts](/docs/configuration/resources.html#timeouts) configuration options:
|
|
|
|
|
|
|
|
- `create` - Default `4 minutes`
|
|
|
|
- `update` - Default `4 minutes`
|
|
|
|
- `delete` - Default `4 minutes`
|
|
|
|
|
2017-07-14 20:32:25 +00:00
|
|
|
## Import
|
|
|
|
|
|
|
|
VM image can be imported using the `name`, e.g.
|
|
|
|
|
|
|
|
```
|
|
|
|
$ terraform import google_compute_image.web-image my-custom-image
|
|
|
|
```
|