Terraform State Recovery¶
The remote-state bucket is versioned and encrypted with a customer-managed KMS key. force_destroy is disabled.
Accidental state object change or deletion¶
- stop all Terraform plan/apply jobs for the affected environment
- identify the state key, for example
platform/prod/terraform.tfstate - inspect S3 object versions and select the last known-good version
- restore that version as the current object
- run
terraform plan -refresh-onlyand review every proposed change - resume normal plans only after the state/resource relationship is understood
Do not blindly run terraform apply to “repair” state.
Stale lock file¶
S3 native locking uses a .tflock object. If Terraform reports a lock:
- confirm no plan/apply job is active
- inspect the lock metadata / job history
- use
terraform force-unlock <LOCK_ID>only when the original operation is definitely gone
Deleting lock objects manually should be a last resort.
KMS key safety¶
KMS key rotation is enabled and deletion uses a 30-day waiting period. Removing access to the KMS key makes encrypted state unreadable even if the S3 object still exists.
Disaster-recovery extension¶
For a real platform, evaluate cross-region S3 replication, a separately controlled backup account, and periodic state-recovery exercises. Those controls are intentionally not enabled automatically in this lab because they add account topology and cost assumptions.