dtcloud_volume (Resource)
Manages a block storage volume.
This resource owns the volume itself: creating it, renaming it, growing it and changing its storage
policy. Attaching it to a machine is a separate resource, dtcloud_vm_volume_attachment. A disk a
machine boots from is not a dtcloud_volume: it comes from the block_device block on
dtcloud_vm.
Example Usage
# A blank data disk.
resource "dtcloud_volume" "data" {
name = "app-data"
size = 100
storage_policy = data.dtcloud_storage_policies.available.policies[0].name
}
# A volume seeded from an image. The source is fixed at create time: changing it
# replaces the volume.
resource "dtcloud_volume" "boot" {
name = "web-01-boot"
size = 40
storage_policy = "standard"
image_id = var.image_id
}
image_id, source_volume_id and source_snapshot_id are mutually exclusive: set one to seed
the volume's contents, or none for a blank volume.
Schema
Required
name(String) Name of the volume. Can be changed in place.size(Number) Size in GB, between 1 and 8192. Can be grown in place; shrinking is impossible and is refused when applied.storage_policy(String) Name of the storage policy backing the volume, as listed by the dtcloud_storage_policies data source. Changing it retypes the volume in place.
Optional
description(String) Free-text description. Write-only: the API accepts it but never reports it back, so it does not drift, does not survive import, and cannot be cleared.image_id(String) Create the volume from this image, making it bootable. Changing it recreates the volume.source_snapshot_id(String) Restore the volume from this snapshot.sizemust be at least the snapshot's size. Changing it recreates the volume.source_volume_id(String) Create the volume as a clone of this one. Changing it recreates the volume.timeouts(Block, Optional) (see below for nested schema)
Read-Only
attached_to(String) Name of the VM this volume is attached to, empty when detached.attached_to_id(String) ID of the VM this volume is attached to, empty when detached.attached_to_status(String) Status of the VM this volume is attached to.bootable(Boolean) Whether the volume can be booted from. True for volumes built from an image.created(String) When the volume was created, as reported by the platform.id(String) The ID of this resource.image_metadata(List of Object) Details of the image this volume was created from. Empty for a blank volume. (see below for nested schema)is_detachable(Boolean) Whether the platform will allow this volume to be detached.last_modified(String) When the volume last changed, as reported by the platform.status(String) Status reported by the platform, e.g. available or in-use.volume_type(String) HDD, or CD-ROM when the volume holds an ISO. Derived by the platform, not the storage policy.
Nested Schema for timeouts
Optional:
create(String)delete(String)update(String)
Nested Schema for image_metadata
Read-Only:
checksum(String)container_format(String)disk_format(String)image_id(String)image_name(String)min_disk(String)min_ram(String)os_distro(String)os_type(String)size(String)
Behaviour worth knowing
An attached volume cannot be deleted. The platform refuses to delete a volume that is
in-use, so the provider checks first and names the machine it is attached to. It will not detach
the volume for you. When the attachment is a dtcloud_vm_volume_attachment that references this
volume, Terraform removes the attachment first on its own.
- What changes in place.
name,description,sizeandstorage_policy. The three sources force a new volume: they seed its contents at create time, and no endpoint seeds an existing one again. sizecan only be grown. A lower value is refused rather than turned into a replacement, which would destroy the data. It is refused at apply, not at plan, because a plan cannot tell a lowered number from a volume grown outside Terraform, and refusing at plan would also blockterraform destroy. If a plan proposes to shrink a volume you did not edit, raisesizeto match.descriptionis write-only. The API never reports it back, so it cannot drift, does not survive an import and cannot be cleared. It is applied by a second call after the volume is created.- Growing and retyping look finished before they are. The volume stays
availablewith its old size or policy for a while, so the provider waits for the value it asked for rather than for the status. storage_policyis a name. A volume created with a volume type id reads back as the name, and every later plan proposes a change.dtcloud_storage_policieslists the names.- Deleting takes the snapshots with it. The delete cascades, so every snapshot of the volume goes
too, including snapshots managed as
dtcloud_snapshot, without a warning from Terraform. Check withdtcloud_volume_snapshotsfirst. Snapshots that reference this volume involume_idare destroyed before it.
Timeouts
create and update each default to 30 minutes, delete to 20 minutes. All three are asynchronous,
and creating from an image or growing a large volume takes a while, so the defaults are generous.
Override them with a timeouts block:
resource "dtcloud_volume" "data" {
# ...
timeouts {
create = "1h"
}
}
Import
terraform import dtcloud_volume.data 8a4f2c15-6b93-4d0e-a7f1-2c5b8e9d3a66
description, image_id, source_volume_id and source_snapshot_id are not reported by the
details endpoint, so they are empty after an import. image_metadata.image_id is not a substitute:
it names the image the contents came from, which a clone or a restore inherits. The three sources
force a new volume, so if the configuration sets one, the first plan after an import proposes a
rebuild. Ignore it to keep the imported volume:
resource "dtcloud_volume" "data" {
# ...
lifecycle {
ignore_changes = [image_id, source_volume_id, source_snapshot_id]
}
}