Volume¶
HtzVolume manages a Hetzner Cloud Volume. Volumes are persistent block storage devices that exist independently of servers and can be formatted on creation.
Type: Hetzner::Storage::Volume
Import: @cdk-x/hetzner
Props¶
| Prop | Type | Required | Create-only | Description |
|---|---|---|---|---|
name |
string |
✅ | — | Volume name. Must be unique within the project. |
size |
number |
✅ | — | Size in GB. Minimum: 10. Maximum: 10240. Can only be increased after creation. |
location |
string |
— | ✅ | Location where the volume is created (e.g. nbg1, fsn1, hel1). Must match the server's location for attachment. |
format |
string |
— | ✅ | Filesystem format applied at creation. One of: xfs, ext4. |
labels |
Record<string, string> |
— | — | Key/value labels. |
Attribute getters¶
| Getter | Resolves to |
|---|---|
attrVolumeId |
The Hetzner-assigned volume ID (integer). |
Create example¶
| src/main.ts | |
|---|---|
- Formatting happens at creation time — it is a
createOnlyProperty. To change the filesystem, destroy the volume and recreate it.
Update behavior¶
| Prop | Updatable | Notes |
|---|---|---|
name |
✅ | Calls PATCH /volumes/{id} |
labels |
✅ | Calls PATCH /volumes/{id} |
size |
Increase only | Calls POST /volumes/{id}/actions/resize. Resize-down is not supported by the Hetzner API — attempting it throws an error. |
location |
❌ | Create-only |
format |
❌ | Create-only |
Destroy behavior¶
The engine calls DELETE /volumes/{id}. All volume data is irreversibly destroyed.
Volume must be detached before deletion
Hetzner requires the volume to be detached from any server before it can be deleted. Make sure no server has the volume attached at destroy time.
Server attachment¶
Volume attachment is not modelled in HtzVolume itself — it is a separate lifecycle concern. serverId and automount are intentionally absent from this construct. A dedicated HtzVolumeAttachment resource will handle attachment in a future release.
For now, ensure the volume and the target server share the same location — this is a Hetzner requirement for attachment.
- Volume location must match the server's location.
- Both resources are in
nbg1— the volume can be attached to this server onceHtzVolumeAttachmentis available.
See also
- Server — compute resource to which a volume can be attached
- Tokens & Cross-resource References — how
attrVolumeIdresolves at deploy time