» google_compute_disk

Persistent disks are durable storage devices that function similarly to the physical disks in a desktop or a server. Compute Engine manages the hardware behind these devices to ensure data redundancy and optimize performance for you. Persistent disks are available as either standard hard disk drives (HDD) or solid-state drives (SSD).

Persistent disks are located independently from your virtual machine instances, so you can detach or move persistent disks to keep your data even after you delete your instances. Persistent disk performance scales automatically with size, so you can resize your existing persistent disks or add more persistent disks to an instance to meet your performance and storage space requirements.

Add a persistent disk to your instance when you need reliable and affordable storage with consistent performance characteristics.

To get more information about Disk, see:

» Example Usage - Disk Basic

resource "google_compute_disk" "default" {
  name  = "test-disk"
  type  = "pd-ssd"
  zone  = "us-central1-a"
  image = "debian-8-jessie-v20170523"
  labels = {
    environment = "dev"
  }
  physical_block_size_bytes = 4096
}

» Argument Reference

The following arguments are supported:

  • name - (Required) Name of the resource. Provided by the client when the resource is created. The name must be 1-63 characters long, and comply with RFC1035. Specifically, the name must be 1-63 characters long and match the regular expression [a-z]([-a-z0-9]*[a-z0-9])? which means the first character must be a lowercase letter, and all following characters must be a dash, lowercase letter, or digit, except the last character, which cannot be a dash.

  • description - (Optional) An optional description of this resource. Provide this property when you create the resource.

  • labels - (Optional) Labels to apply to this disk. A list of key->value pairs.

  • size - (Optional) Size of the persistent disk, specified in GB. You can specify this field when creating a persistent disk using the sourceImage or sourceSnapshot parameter, or specify it alone to create an empty persistent disk. If you specify this field along with sourceImage or sourceSnapshot, the value of sizeGb must not be less than the size of the sourceImage or the size of the snapshot.

  • physical_block_size_bytes - (Optional) Physical block size of the persistent disk, in bytes. If not present in a request, a default value is used. Currently supported sizes are 4096 and 16384, other sizes may be added in the future. If an unsupported value is requested, the error message will list the supported values for the caller's project.

  • type - (Optional) URL of the disk type resource describing which disk type to use to create the disk. Provide this when creating the disk.

  • image - (Optional) The image from which to initialize this disk. This can be one of: the image's self_link, projects/{project}/global/images/{image}, projects/{project}/global/images/family/{family}, global/images/{image}, global/images/family/{family}, family/{family}, {project}/{family}, {project}/{image}, {family}, or {image}. If referred by family, the images names must include the family name. If they don't, use the google_compute_image data source. For instance, the image centos-6-v20180104 includes its family name centos-6. These images can be referred by family name here.

  • zone - (Optional) A reference to the zone where the disk resides.

  • source_image_encryption_key - (Optional) The customer-supplied encryption key of the source image. Required if the source image is protected by a customer-supplied encryption key. Structure is documented below.

  • disk_encryption_key - (Optional) Encrypts the disk using a customer-supplied encryption key. After you encrypt a disk with a customer-supplied key, you must provide the same key if you use the disk later (e.g. to create a disk snapshot or an image, or to attach the disk to a virtual machine). Customer-supplied encryption keys do not protect access to metadata of the disk. If you do not provide an encryption key when creating the disk, then the disk will be encrypted using an automatically generated key and you do not need to provide a key to use the disk later. Structure is documented below.

  • snapshot - (Optional) The source snapshot used to create this disk. You can provide this as a partial or full URL to the resource. For example, the following are valid values:

  • source_snapshot_encryption_key - (Optional) The customer-supplied encryption key of the source snapshot. Required if the source snapshot is protected by a customer-supplied encryption key. Structure is documented below.

  • project - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used.

The source_image_encryption_key block supports:

The disk_encryption_key block supports:

The source_snapshot_encryption_key block supports:

» Attributes Reference

In addition to the arguments listed above, the following computed attributes are exported:

  • label_fingerprint - The fingerprint used for optimistic locking of this resource. Used internally during updates.

  • creation_timestamp - Creation timestamp in RFC3339 text format.

  • last_attach_timestamp - Last attach timestamp in RFC3339 text format.

  • last_detach_timestamp - Last dettach timestamp in RFC3339 text format.

  • users - Links to the users of the disk (attached instances) in form: project/zones/zone/instances/instance

  • source_image_id - The ID value of the image used to create this disk. This value identifies the exact image that was used to create this persistent disk. For example, if you created the persistent disk from an image that was later deleted and recreated under the same name, the source image ID would identify the exact version of the image that was used.

  • source_snapshot_id - The unique ID of the snapshot used to create this disk. This value identifies the exact snapshot that was used to create this persistent disk. For example, if you created the persistent disk from a snapshot that was later deleted and recreated under the same name, the source snapshot ID would identify the exact version of the snapshot that was used.

  • self_link - The URI of the created resource.

» Timeouts

This resource provides the following Timeouts configuration options:

  • create - Default is 5 minutes.
  • update - Default is 4 minutes.
  • delete - Default is 4 minutes.

» Import

Disk can be imported using any of these accepted formats:

$ terraform import google_compute_disk.default projects/{{project}}/zones/{{zone}}/disks/{{name}}
$ terraform import google_compute_disk.default {{project}}/{{zone}}/{{name}}
$ terraform import google_compute_disk.default {{name}}