Hetzner.Firewall reference
Firewall
Section titled “Firewall”Source:
packages/hetzner/src/Firewall.ts
A Hetzner Cloud firewall — a named set of inbound/outbound rules that can be applied to one or more Servers.
Name, rules, labels, and applyTo are all mutable. Changing the name
updates the existing firewall in place (it is unique per project).
Firewall: Creating a Firewall
Section titled “Firewall: Creating a Firewall”Basic firewall
const web = yield* Hetzner.Firewall("web", { rules: [ { direction: "in", protocol: "tcp", port: "22", sourceIps: ["0.0.0.0/0", "::/0"], }, ],});Firewall applied to a Server
const server = yield* Hetzner.Server("app", { image: "ubuntu-24.04", serverType: "cx22", location: "nbg1",});const web = yield* Hetzner.Firewall("web", { applyTo: [server], rules: [ { direction: "in", protocol: "tcp", port: "443", sourceIps: ["0.0.0.0/0", "::/0"], }, ],});Firewall: Updating rules
Section titled “Firewall: Updating rules”const web = yield* Hetzner.Firewall("web", { rules: [ { direction: "in", protocol: "tcp", port: "80", sourceIps: ["0.0.0.0/0", "::/0"], }, { direction: "in", protocol: "tcp", port: "443", sourceIps: ["0.0.0.0/0", "::/0"], }, ],});Firewall: Looking up an existing firewall
Section titled “Firewall: Looking up an existing firewall”Firewall.lookup references a firewall Alchemy doesn’t manage (created in
the Hetzner Console or by another stack). It is read during plan/deploy,
never created, updated or deleted.
const firewall = Hetzner.Firewall.lookup({ name: "web" });