opentofu: a ssh_public_key change must not replace the instances #611

Stängd
öppnade 2026-10-08 21:12:22 +00:00 av supernaut · 0 kommentarer
Ägare

What

var.ssh_public_key is rendered into the instance user_data (opentofu/compute.tofu:136-148, monitoring.tofu:164-176). user_data is ForceNew. The hostname was already decoupled for this reason (variables.tofu). Neither instance has a lifecycle block. Only the volumes do.

Why

A key rotation should not rebuild the host.

Failing case

Change ssh_public_key in terraform.tfvars and run pnpm tofu:apply. The plan shows both instances must be replaced plus the volume attachments, which is prod downtime. cloud-init on the retained root disk only appends the new key to admin. The old key is not revoked, so the rebuild does not even do the job.

Fix

Add lifecycle { ignore_changes = [user_data] } to both instances, with a one-line why-comment. Rotate keys through the Ansible authorized_key task.

Done when

  • tofu plan after a key change shows no instance replacement.
  • The runbook describes the rotation path through Ansible.
  • pnpm tofu:validate and tofu:check pass.
## What `var.ssh_public_key` is rendered into the instance `user_data` (`opentofu/compute.tofu:136-148`, `monitoring.tofu:164-176`). `user_data` is ForceNew. The hostname was already decoupled for this reason (`variables.tofu`). Neither instance has a `lifecycle` block. Only the volumes do. ## Why A key rotation should not rebuild the host. ## Failing case Change `ssh_public_key` in `terraform.tfvars` and run `pnpm tofu:apply`. The plan shows both instances `must be replaced` plus the volume attachments, which is prod downtime. cloud-init on the retained root disk only appends the new key to `admin`. The old key is not revoked, so the rebuild does not even do the job. ## Fix Add `lifecycle { ignore_changes = [user_data] }` to both instances, with a one-line why-comment. Rotate keys through the Ansible `authorized_key` task. ## Done when - [ ] `tofu plan` after a key change shows no instance replacement. - [ ] The runbook describes the rotation path through Ansible. - [ ] `pnpm tofu:validate` and `tofu:check` pass.
Logga in för att delta i denna konversation.
Ingen milstolpe
Inga tilldelade
1 deltagare
Notiser
Förfallodatum
Förfallodatumet är ogiltigt eller utanför gränserna. Använd formatet "åååå-mm-dd".

Inget förfallodatum satt.

Beroenden

Inga beroenden satta

Referens
bitborg/bitborg-infra#611
Ingen beskrivning angiven.