tofu: rename from terraform, state in its own bucket, Loki buckets
All checks were successful
nixos / nixos (push) Successful in 34s

The infrastructure is applied with OpenTofu; name it so. terraform/
becomes tofu/, the files end in .tofu (OpenTofu 1.8+ prefers them), the
local variables file is secrets.auto.tfvars, and both servers carry
managed_by=opentofu (an in-place label change).

The state moved to new buckets asxpio-tofu-main/-repl, key
tofu/state/tofu.tfstate, with `tofu init -migrate-state`; a plan against
it shows no changes. The old asxpio-terraform-* buckets stay, renamed
in the config with moved blocks, until the new state has been used for
a while.

asxpio-loki-main, created by hand, is adopted with an import block, and
a new asxpio-loki-repl in fsn1 receives it in the daily replica, which
now also copies the new state bucket instead of the old one.

What keeps the Terraform name is OpenTofu's own: the `terraform {}`
block and .terraform.lock.hcl.

Assisted-by: Claude:opus-5-5
This commit is contained in:
Sergei Poljanski 2026-11-17 09:42:53 +04:00
commit 796331815d
Signed by: asxpi
GPG key ID: 4F8851660FA4121B

View file

@ -1,102 +0,0 @@
# ASXP.IO Infrastructure
Hetzner Cloud infrastructure, managed with [OpenTofu](https://opentofu.org)
(`tofu`; the dev shell of `../nixos` has it). The files are plain HCL and
the state is the one Terraform wrote; `.terraform.lock.hcl` pins the
providers and is committed.
## 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)
**Terraform State:**
- asxpio-terraform-main (hel1)
- asxpio-terraform-repl (fsn1)
**Backups:**
- asxpio-backups-main (hel1)
- asxpio-backups-repl (fsn1)
**Logs:**
- asxpio-loki-main (hel1): Loki chunks; created by hand, not in Terraform
## DNS
`dns.tf` 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 `terraform 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
```bash
cp terraform.tfvars.example terraform.tfvars # token and Object Storage keys
export AWS_ACCESS_KEY_ID=... AWS_SECRET_ACCESS_KEY=... # state bucket
tofu init
tofu plan
tofu apply
```
In a new project the state bucket does not exist yet: comment out the
`backend "s3"` block in `providers.tf` for the first apply, restore it,
then `tofu init -migrate-state`.
Coming from Terraform: `tofu init -reconfigure` once; nothing in the
state changes.
## Files
- `servers.tf` - Server definitions, cloud-init variables
- `s3.tf` - S3 buckets (6 total)
- `vpc.tf` - Private network
- `firewall.tf` - Security rules
- `dns.tf` - DNS zones and records
- `keys.tf` - SSH keys
- `cloud-init/nixos.yaml.tftpl` - first boot: Debian to NixOS