Floating IP Assignment¶
HtzFloatingIpAssignment assigns a Hetzner Cloud Floating IP to a Server. It models the assignment as a first-class resource with its own lifecycle — create assigns, update reassigns to a different server, and destroy unassigns.
Type: Hetzner::Networking::FloatingIpAssignment
Import: @cdk-x/hetzner
Props¶
| Prop | Type | Required | Description |
|---|---|---|---|
floatingIpId |
number \| IResolvable |
✅ | ID of the floating IP to assign. Typically supplied via attrFloatingIpId from an HtzFloatingIp. |
serverId |
number \| IResolvable |
✅ | ID of the server to assign the floating IP to. Typically supplied via attrServerId from an HtzServer. |
No attribute getters
HtzFloatingIpAssignment has no attr* getters — its primary identifier is the floatingIpId, which you already hold from HtzFloatingIp.attrFloatingIpId.
Create example¶
attrFloatingIpIdproduces a{ ref, attr }token — the engine resolves it afterHtzFloatingIpis created and injects the numeric ID. The assignment automatically depends on the floating IP.- Same for
attrServerId— the assignment waits for the server to be ready before assigning.
Cross-stack example¶
When the floating IP lives in a different stack (e.g. a shared networking stack), export it via StackOutput and import the value:
- The token is a cross-stack reference. The engine resolves it at deploy time once
Networkinghas been deployed. importValue()creates a cross-stack token that encodes the dependency — the engine deploysNetworkingbeforeCompute.
Dependency graph¶
The engine infers dependencies from the { ref, attr } tokens — no manual addDependency() call is needed:
Update behavior¶
Changing serverId triggers an unassign-then-reassign sequence:
- Engine calls
POST /floating_ips/{id}/actions/unassign— waits for the action to complete. - Engine calls
POST /floating_ips/{id}/actions/assignwith the newserverId— waits for the action to complete.
This allows you to move a reserved public IP between servers (e.g. during a blue/green deploy) without recreating the HtzFloatingIp resource.
Brief routing gap during reassignment
Traffic to the floating IP address will not be routed during the window between unassign and reassign. Keep this in mind for production workloads.
Destroy behavior¶
The engine calls POST /floating_ips/{id}/actions/unassign and waits for the Hetzner action to reach success. The underlying floating IP is not deleted — only the assignment is removed.
Destroy order
When HtzFloatingIp and HtzFloatingIpAssignment are in the same stack, the engine destroys HtzFloatingIpAssignment first (because HtzFloatingIp depends on it indirectly via the token). If they are in separate stacks, destroy the compute stack before the networking stack.
See also
- Floating IP — the IP resource being assigned
- Server — the compute resource receiving the IP
- Tokens & Cross-resource References — how
attrFloatingIpIdandattrServerIdresolve at deploy time - Volume Attachment — same pattern applied to block storage