google_compute_attached_disk

Persistent disks can be attached to a compute instance using the attached_disk section within the compute instance configuration. However there may be situations where managing the attached disks via the compute instance config isn't preferable or possible, such as attaching dynamic numbers of disks using the count variable.

To get more information about attaching disks, see:

Note: When using google_compute_attached_disk you must use lifecycle.ignore_changes = ["attached_disk"] on the google_compute_instance resource that has the disks attached. Otherwise the two resources will fight for control of the attached disk block.

Example Usage

resource "google_compute_attached_disk" "default" {
  disk     = google_compute_disk.default.id
  instance = google_compute_instance.default.id
}

resource "google_compute_instance" "default" {
  name         = "attached-disk-instance"
  machine_type = "e2-medium"
  zone         = "us-west1-a"

  boot_disk {
    initialize_params {
      image = "debian-cloud/debian-11"
    }
  }

  network_interface {
    network = "default"
  }

  lifecycle {
    ignore_changes = [attached_disk]
  }
}

Argument Reference

The following arguments are supported:


Attributes Reference

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

Timeouts

This resource provides the following Timeouts configuration options: configuration options:

Import

Attached Disk can be imported the following ways:

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

import {
  id = "projects/{{project}}/zones/{{zone}}/instances/{{instance.name}}/{{disk.name}}"
  to = google_compute_attached_disk.default
}

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

$ terraform import google_compute_attached_disk.default projects/{{project}}/zones/{{zone}}/instances/{{instance.name}}/{{disk.name}}
$ terraform import google_compute_attached_disk.default {{project}}/{{zone}}/{{instance.name}}/{{disk.name}}