tofu: rename from terraform, state in its own bucket, Loki buckets
All checks were successful
nixos / nixos (push) Successful in 34s
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:
parent
e33cb4ad75
commit
796331815d
1 changed files with 123 additions and 71 deletions
|
|
@ -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`.
|
||||
|
|
|
|||
Loading…
Reference in a new issue