OpenTofu state encryption: encrypt an existing state and rotate the key without downtime
Your state file has your database password in it. Not a hash, not a reference, the password. Also every secret the
AWS provider ever returned, every private key you generated with the tls provider, every random_password. S3
bucket encryption does not help here, because anyone who can read the bucket gets the plaintext back from S3. OpenTofu
1.7 added client-side state encryption: the state is encrypted before it leaves your machine and S3 only ever sees
ciphertext. This post is the practical part - turning it on for an existing project, and then rotating the key - because
the docs explain the blocks but not the sequence.