Server
Source:
src/Hetzner/Server.ts
A Hetzner Cloud Server — a virtual machine in a Location, created from
a Server type and an Image. serverType, image, and location are
immutable (changing any of them replaces the Server). Name, labels,
delete protection, and (when set) Networks / Firewalls / Volumes /
Placement Group update in place. SSH keys are injected only at create.
Creating a Server
Section titled “Creating a Server”Basic Server
const server = yield* Hetzner.Server("web", { serverType: "cpx12", image: "ubuntu-24.04", location: "nbg1",});Named Server with labels
const server = yield* Hetzner.Server("web", { name: "app-web", serverType: "cpx12", image: "ubuntu-24.04", location: "nbg1", labels: { role: "web" },});Attachments
Section titled “Attachments”const key = yield* Hetzner.SshKey("deploy", { publicKey: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI… user@host",});const group = yield* Hetzner.PlacementGroup("web");const server = yield* Hetzner.Server("web", { serverType: "cpx12", image: "ubuntu-24.04", location: "nbg1", sshKeys: [key], placementGroup: group,});Custom init script
Section titled “Custom init script”Install packages on first boot
const server = yield* Hetzner.Server("web", { serverType: "cpx12", image: "ubuntu-24.04", userData: `#!/bin/bashapt-get updateDEBIAN_FRONTEND=noninteractive apt-get install -y nginxsystemctl enable --now nginx`,});cloud-config document
const server = yield* Hetzner.Server("web", { serverType: "cpx12", image: "ubuntu-24.04", userData: `#cloud-configpackages: - nginx - postgresql-client`,});userData is merged with Alchemy’s own bootstrap script into a
multipart cloud-init document, so both run. It is applied on first boot
only — changing it replaces the Server.