Skip to main content

dtcloud_vm_volume_attachment (Resource)

Attaches an existing volume to a virtual machine.

The attachment is its own resource rather than a block on dtcloud_vm because it has its own lifecycle: a volume can be detached and attached elsewhere without touching the machine or the volume. The resource ID is <vm-id>:<volume-id>.

Example Usage​

# The volume and the machine each have their own resource; this is only the
# attachment between them, so the volume can be detached and re-attached
# elsewhere without either being rebuilt.
resource "dtcloud_vm_volume_attachment" "data" {
vm_id = dtcloud_vm.web.id
volume_id = dtcloud_volume.data.id
}

Schema​

Required​

  • vm_id (String) ID of the virtual machine to attach to. Changing this forces a new resource to be created.
  • volume_id (String) ID of the existing volume to attach. Changing this forces a new resource to be created.

Optional​

Read-Only​

  • id (String) The ID of this resource.
  • size (Number) Size of the attached volume in GB.
  • storage_policy (String) Storage policy / volume type of the attached volume.
  • volume_name (String) Name of the attached volume.

Nested Schema for timeouts​

Optional:

  • create (String)
  • delete (String)

Behaviour worth knowing​

warning

Detaching does not unmount. Detaching a volume that is mounted inside the guest can lose data. Terraform does not stop the machine or unmount anything first.

  • There is nothing to update. An attachment is made or broken, so every argument forces a new one.
  • The volume must already exist. Create it with dtcloud_volume; this resource only attaches it.
  • A volume detached outside Terraform drops the attachment from state, and the next plan attaches it again.
  • dtcloud_vm.volume is a snapshot from that resource's last refresh. A volume attached here in the same apply appears there after the next refresh; read this resource's attributes instead.
  • A running guest can refuse a detach. The platform accepts the request and then asks the guest to release the disk. A filesystem that is still mounted makes it give up and put the volume back, and the destroy fails saying so. Unmount the filesystem in the guest, or stop the machine, and apply again.

Timeouts​

create and delete each default to 10 minutes. Attaching and detaching are asynchronous: the provider waits for the attachment to appear on the machine, and for the volume's own status to leave detaching. Override them with a timeouts block:

resource "dtcloud_vm_volume_attachment" "data" {
# ...

timeouts {
create = "30m"
}
}

Import​

# <vm-id>:<volume-id>
terraform import dtcloud_vm_volume_attachment.data 4c9a1f37-8d25-4e60-b13f-6a7c2e5b9d88:8a4f2c15-6b93-4d0e-a7f1-2c5b8e9d3a66