Skip to content

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.

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" },
});
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,
});

Install packages on first boot

const server = yield* Hetzner.Server("web", {
serverType: "cpx12",
image: "ubuntu-24.04",
userData: `#!/bin/bash
apt-get update
DEBIAN_FRONTEND=noninteractive apt-get install -y nginx
systemctl enable --now nginx`,
});

cloud-config document

const server = yield* Hetzner.Server("web", {
serverType: "cpx12",
image: "ubuntu-24.04",
userData: `#cloud-config
packages:
- 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.