iac/tofu
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-11-19 05:53:05 +00:00
..
cloud-init tofu: rename from terraform, state in its own bucket, Loki buckets 2026-11-17 09:42:53 +04:00
.gitignore tofu: rename from terraform, state in its own bucket, Loki buckets 2026-11-17 09:42:53 +04:00
.terraform.lock.hcl deps: Update Terraform minio to v3.46.4 2026-11-19 05:53:05 +00:00
dns.tofu tofu: rename from terraform, state in its own bucket, Loki buckets 2026-11-17 09:42:53 +04:00
firewall.tofu tofu: rename from terraform, state in its own bucket, Loki buckets 2026-11-17 09:42:53 +04:00
keys.tofu tofu: rename from terraform, state in its own bucket, Loki buckets 2026-11-17 09:42:53 +04:00
outputs.tofu tofu: rename from terraform, state in its own bucket, Loki buckets 2026-11-17 09:42:53 +04:00
providers.tofu tofu: rename from terraform, state in its own bucket, Loki buckets 2026-11-17 09:42:53 +04:00
README.md nixos: drop the rehearsal pair and other migration leftovers 2026-11-17 11:11:33 +04:00
s3.tofu nixos: drop the rehearsal pair and other migration leftovers 2026-11-17 11:11:33 +04:00
secrets.auto.tfvars.example tofu: rename from terraform, state in its own bucket, Loki buckets 2026-11-17 09:42:53 +04:00
servers.tofu nixos: drop the rehearsal pair and other migration leftovers 2026-11-17 11:11:33 +04:00
variables.tofu tofu: rename from terraform, state in its own bucket, Loki buckets 2026-11-17 09:42:53 +04:00
vpc.tofu tofu: rename from terraform, state in its own bucket, Loki buckets 2026-11-17 09:42:53 +04:00

ASXP.IO Infrastructure

Hetzner Cloud infrastructure, managed with OpenTofu (tofu; the dev shell of ../nixos has it). The files are plain HCL and the state lives in Object Storage (asxpio-tofu-main, key tofu/state/tofu.tfstate); .terraform.lock.hcl (OpenTofu keeps that name) pins the providers and is committed. Files end in .tofu.

Servers

  • asxpio-ops (CX23: 2 vCPU, 4GB) - Traefik, Forgejo, app stacks
  • asxpio-services (CX43: 8 vCPU, 16GB) - CI runner, game servers, SillyTavern

Both have delete and rebuild protection. Hetzner's server backups are off; restic backs up the data instead (see ../README.md).

Both servers carry prevent_destroy and ignore changes to user_data, image and ssh_keys, because hcloud would replace a running server when those change.

A new server boots Debian and converts itself to NixOS: its cloud-init (cloud-init/nixos.yaml.tftpl, one template for both) runs a pinned nixos-infect and reboots into a bare NixOS, about three minutes after creation. The system's configuration then comes from ../nixos. Edits to the template reach a server only when it is created or rebuilt in place; both procedures are in ../nixos/README.md.

Storage (S3-compatible)

OpenTofu state:

  • asxpio-tofu-main (hel1), replicated daily to asxpio-tofu-repl (fsn1)
  • asxpio-terraform-main / -repl: where the state lived until 2026-11-17; kept for now (legacy_state_*), to be emptied and removed

Backups:

  • asxpio-backups-main (hel1), replicated to asxpio-backups-repl (fsn1), except restic/ (restic writes both itself)

Logs:

  • asxpio-loki-main (hel1): Loki's chunks, replicated to asxpio-loki-repl (fsn1)

The daily replica runs on asxpio-services (nixos/hosts/asxpio-services/replica.nix).

DNS

dns.tofu holds the zones asxp.io and czsk.it (Hetzner DNS, this project) and every record set except SOA and NS. Our servers' records reference hcloud_server, so moving a service is one edit.

All record sets are change-protected except the test XMPP servers' (prosody, ejabberd, anotherim); both zones are delete-protected. To change a protected record set, apply twice: first with the set excluded from protection, then with the new value. Hand edits in the console show up as drift in tofu plan.

Network

  • VPC: 10.10.0.0/20
  • WireGuard VPN: 10.20.0.0/24
  • IPv4 + IPv6 enabled

Cost

Item Monthly
ops CX23 €3.99
services CX43 €11.99
IPv4 (2x) €1.00
S3 (1TB) €6.49
S3 1TB Traffic €1.00
Total €24.47

Prices are net, as billed in November 2026 (0% VAT).

Both servers are billed below the current list price (€5.49 and €15.99). A deleted and recreated server gets the list price, so reinstall or rebuild in place and never recreate. prevent_destroy and Hetzner's delete protection guard against it.

Setup

cp secrets.auto.tfvars.example secrets.auto.tfvars   # token and Object Storage keys
export AWS_ACCESS_KEY_ID=... AWS_SECRET_ACCESS_KEY=...   # state bucket
tofu init
tofu plan
tofu apply

First run: the state bucket

The state bucket asxpio-tofu-main is itself a resource here (s3.tofu), so in a new project tofu init fails: the backend points at a bucket that doesn't exist yet. Bootstrap it once with local state:

# 1. comment out the backend "s3" block in providers.tofu
tofu init
tofu apply -target=minio_s3_bucket.state_main   # just the bucket
# 2. restore the backend block
tofu init -migrate-state                        # copies local state into the bucket
rm terraform.tfstate*                           # S3 holds it now
tofu apply                                      # everything else

The bucket holds the state that manages it, so it carries prevent_destroy: a plan that would delete it fails instead.

Files

  • servers.tofu - Server definitions, cloud-init variables
  • s3.tofu - Object Storage buckets
  • vpc.tofu - Private network
  • firewall.tofu - Security rules
  • dns.tofu - DNS zones and records
  • keys.tofu - SSH keys
  • cloud-init/nixos.yaml.tftpl - first boot: Debian to NixOS