Interview Prep/Terraform/Lost, Corrupted and Drifted State

Terraform state shows an S3 bucket, but `aws s3api head-bucket` returns 404, and the plan still shows no changes.

AdvancedTroubleshootingLost, Corrupted and Drifted State
Answer

Likely causes → You ran terraform plan -refresh=false or a CI wrapper disables refresh; the provider is pointed at a different region/account from where the bucket was; a provider alias mismatch makes the refresh query the wrong endpoint.

Diagnose →

terraform state show aws_s3_bucket.logs | grep -E 'region|arn'
aws sts get-caller-identity
grep -rn 'refresh=false' .github/ scripts/

Fix → Plan with refresh enabled using the correct provider configuration. Terraform will then notice the bucket is gone and plan a create.

Prevent → Only use -refresh=false for speed on very large stacks when you also run scheduled full-refresh drift checks.

All Terraform questions Roadmap: Terraform in production

More on Lost, Corrupted and Drifted State