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
2 changed files with 123 additions and 71 deletions

View file

@ -1,7 +1,7 @@
# NixOS
Each server's whole system, as one flake. A server is created by OpenTofu
(`../terraform`), converts itself to NixOS on first boot, and gets its
(`../tofu`, OpenTofu), converts itself to NixOS on first boot, and gets its
configuration from here. Production is moving over from `../ansible`;
the plan and its state are in `../MIGRATION.md`.
@ -56,7 +56,7 @@ Try anything risky on the rehearsal pair first (below).
## Building the servers from scratch
What you need: a Hetzner Cloud project and its API token, Object Storage
keys (hel1 and fsn1), an SSH key listed in `../terraform/keys.tf`, and,
keys (hel1 and fsn1), an SSH key listed in `../tofu/keys.tofu`, and,
to restore data, the restic password (`../RESTORE.md`).
The existing servers are billed below today's list price, and a new
@ -67,8 +67,8 @@ place" below**; this section is for a new project or a lost server.
servers):
```sh
cd terraform
cp terraform.tfvars.example terraform.tfvars # fill in the token and keys
cd tofu
cp secrets.auto.tfvars.example secrets.auto.tfvars # fill in the token and keys
export AWS_ACCESS_KEY_ID=... AWS_SECRET_ACCESS_KEY=... # for the state bucket
tofu init
tofu apply
@ -79,7 +79,7 @@ place" below**; this section is for a new project or a lost server.
`tofu init -migrate-state`.
2. **Wait about four minutes.** Each server boots Debian, and cloud-init
(`../terraform/cloud-init/nixos.yaml.tftpl`) runs a pinned
(`../tofu/cloud-init/nixos.yaml.tftpl`) runs a pinned
nixos-infect, which installs NixOS over the running system and
reboots. The result is a bare NixOS: root login with the keys from
`keys.tf`, public and private network, nothing else.
@ -126,7 +126,7 @@ place" below**; this section is for a new project or a lost server.
Keeps the server, its addresses and its price; **wipes the disk**.
```sh
cd terraform
cd tofu
hcloud server disable-protection asxpio-services rebuild
tofu output -json user_data | jq -r '."asxpio-services"' |
hcloud server rebuild --image debian-13 --user-data-from-file - asxpio-services
@ -174,8 +174,8 @@ Two servers on a private network with the production addresses:
```sh
hcloud network create --name rehearsal --ip-range 10.10.0.0/20
hcloud network add-subnet rehearsal --type cloud --network-zone eu-central --ip-range 10.10.0.0/23
tofu -chdir=../terraform output -json user_data | jq -r '."asxpio-ops"' > /tmp/ops.yaml
tofu -chdir=../terraform output -json user_data | jq -r '."asxpio-services"' > /tmp/services.yaml
tofu -chdir=../tofu output -json user_data | jq -r '."asxpio-ops"' > /tmp/ops.yaml
tofu -chdir=../tofu output -json user_data | jq -r '."asxpio-services"' > /tmp/services.yaml
hcloud server create --name rehearsal-ops --type cx23 --image debian-13 --location hel1 \
--ssh-key <your key> --network rehearsal --user-data-from-file /tmp/ops.yaml
hcloud server create --name rehearsal-services --type cx23 --image debian-13 --location hel1 \
@ -199,7 +199,7 @@ carries production credentials.
## How the first boot works, and its limits
- nixos-infect is pinned by commit and checksum in
`../terraform/servers.tf`; it replaces the operating system, so bump it
`../tofu/servers.tofu`; it replaces the operating system, so bump it
deliberately and rehearse.
- It keeps the Debian image's partitions (`modules/hetzner.nix` matches
them) and moves the old system to `/old-root`.

View file

@ -14,8 +14,12 @@ let
exclude = [ "restic/**" ];
}
{
src = "asxpio-terraform-main";
dst = "asxpio-terraform-repl";
src = "asxpio-tofu-main"; # OpenTofu state
dst = "asxpio-tofu-repl";
}
{
src = "asxpio-loki-main"; # Loki's chunks
dst = "asxpio-loki-repl";
}
{
src = "k8s-asxpio-main";