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:

Open in Cloud Shell

Example Usage - Disk Basic

resource "google_compute_disk" "default" {
  name  = "test-disk"
  type  = "pd-ssd"
  zone  = "us-central1-a"
  image = "debian-11-bullseye-v20220719"
  labels = {
    environment = "dev"
  }
  physical_block_size_bytes = 4096
}
Open in Cloud Shell

Example Usage - Disk Async

resource "google_compute_disk" "primary" {
  name  = "async-test-disk"
  type  = "pd-ssd"
  zone  = "us-central1-a"

  physical_block_size_bytes = 4096
}

resource "google_compute_disk" "secondary" {
  name  = "async-secondary-test-disk"
  type  = "pd-ssd"
  zone  = "us-east1-c"

  async_primary_disk {
    disk = google_compute_disk.primary.id
  }

  physical_block_size_bytes = 4096
}
Open in Cloud Shell

Example Usage - Disk Features

resource "google_compute_disk" "default" {
  name  = "test-disk-features"
  type  = "pd-ssd"
  zone  = "us-central1-a"
  labels = {
    environment = "dev"
  }

  guest_os_features {
    type = "SECURE_BOOT"
  }

  guest_os_features {
    type = "MULTI_IP_SUBNET"
  }

  guest_os_features {
    type = "WINDOWS"
  }

  licenses = ["https://www.googleapis.com/compute/v1/projects/windows-cloud/global/licenses/windows-server-core"]

  physical_block_size_bytes = 4096
}

Argument Reference

The following arguments are supported:


The async_primary_disk block supports:

The guest_os_features block supports:

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:

Timeouts

This resource provides the following Timeouts configuration options:

Import

Disk can be imported using any of these accepted formats:

In Terraform v1.5.0 and later, use an import block to import Disk using one of the formats above. For example:

import {
  id = "projects/{{project}}/zones/{{zone}}/disks/{{name}}"
  to = google_compute_disk.default
}

When using the terraform import command, Disk can be imported using one of the formats above. For example:

$ 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 {{zone}}/{{name}}
$ terraform import google_compute_disk.default {{name}}

User Project Overrides

This resource supports User Project Overrides.