Server¶
HtzServer manages a Hetzner Cloud virtual machine. Servers are created from a base image, assigned a server type (size), and optionally attached to private networks, SSH keys, and firewalls.
Type: Hetzner::Compute::Server
Import: @cdk-x/hetzner
Props¶
| Prop | Type | Required | Description |
|---|---|---|---|
name |
string |
✅ | Server name. Must be unique per project and a valid hostname (RFC 1123). |
serverType |
ServerType |
✅ | Server size. See ServerType enum below. |
image |
string |
✅ | OS image to boot from. Use image name (e.g. ubuntu-24.04) or image ID. |
location |
Location |
— | Hetzner location (datacenter). Mutually exclusive with datacenter. |
sshKeys |
string[] |
— | SSH key names or IDs to inject at creation. |
networks |
(number \| IResolvable)[] |
— | Network IDs to attach the server to at creation time. |
userData |
string |
— | Cloud-Init user data script (max 32 KiB). |
labels |
Record<string, string> |
— | Key/value labels. |
publicNet |
ServerPublicNet |
— | Configure or disable the public IPv4/IPv6 interface. |
startAfterCreate |
boolean |
— | Automatically power on the server after creation (default: true). |
volumes |
(number \| IResolvable)[] |
— | Volume IDs to attach. Volumes must be in the same location. |
placementGroupId |
number \| IResolvable |
— | ID of the placement group to assign the server to. Use HtzPlacementGroup.attrPlacementGroupId to reference a managed group. Create-only. |
ServerType enum (selected)¶
| Value | vCPU | RAM | Architecture |
|---|---|---|---|
ServerType.CX22 |
2 | 4 GB | Shared Intel |
ServerType.CX32 |
4 | 8 GB | Shared Intel |
ServerType.CPX11 |
2 | 2 GB | Shared AMD |
ServerType.CAX11 |
2 | 4 GB | Shared Arm64 |
ServerType.CCX13 |
2 | 8 GB | Dedicated vCPU |
Full list available in the ServerType enum exported from @cdk-x/hetzner.
Location enum¶
| Value | Datacenter |
|---|---|
Location.FSN1 |
Falkenstein, Germany |
Location.NBG1 |
Nuremberg, Germany |
Location.HEL1 |
Helsinki, Finland |
Location.ASH |
Ashburn, VA, USA |
Location.HIL |
Hillsboro, OR, USA |
Location.SIN |
Singapore |
Attribute getters¶
| Getter | Resolves to |
|---|---|
attrServerId |
The Hetzner-assigned server ID (integer). |
Create example¶
- Network and subnet are deployed first — server depends on them via the
networkstoken. cx22= 2 vCPU / 4 GB RAM shared Intel. See the table above for all types.- SSH key name to inject. Use
sshKey.attrNameif the key is managed byHtzSshKeyin the same stack — the engine will deploy the key first. - Attaches the server to the private network at creation — it will receive an IP from
10.0.1.0/24. - Cloud-Init script runs once on first boot. Limited to 32 KiB.
Cross-resource reference example¶
Reference a server's ID from another resource (e.g. a floating IP or volume attachment):
attrServerIdresolves to{ ref: "ComputeStackServerXXXX", attr: "serverId" }— the engine assigns the floating IP after the server is created.
Disable public network¶
For servers that should only be reachable via the private network:
- Disabling the public interface is recommended for database or internal servers. The server is only reachable from the private network.
Destroy behavior¶
The engine calls DELETE /servers/{id}. This powers off and permanently deletes the server and its root disk. Attached volumes are not deleted — they are detached and retained unless destroyed separately.
Data loss
Destroying a server permanently deletes the root disk. Back up any data you need before running cdkx destroy.
See also
- Network — create a private network first
- Subnet — subnet the server attaches to
- SSH Key — manage SSH keys as constructs
- Placement Group — spread servers across physical hosts
- Certificate — TLS certificates for HTTPS
- Deployment Lifecycle — creation order