State was deleted or corrupted. How do you recover?
AdvancedProductionState and Backends in Production
Answer
With S3 versioning, list object versions of the key and restore the last good one (copy that version over the current object, or delete the delete marker). Then terraform plan should show no diff. Without versioning you are left with terraform import for every resource, which is why versioning, replication and a restore drill are non-negotiable. Run terraform state pull backups nightly in sensitive stacks.
aws s3api list-object-versions --bucket acme-tfstate --prefix prod/network/
aws s3api copy-object --bucket acme-tfstate --key prod/network/terraform.tfstate \
--copy-source "acme-tfstate/prod/network/terraform.tfstate?versionId=<id>"
More on State and Backends in Production
Why should Terraform state never be committed to Git?BeginnerHow do you bootstrap the remote backend, given the bucket must exist before Terraform can use it?IntermediateWhat does a hardened S3 state bucket look like?IntermediateWhat is the minimum IAM permission set for the S3 backend?IntermediateHow do you move from DynamoDB locking to S3 native locking in a live fleet?IntermediateHow do you split a monolithic state and what drives blast-radius decisions?Advanced