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.
More on Lost, Corrupted and Drifted State
Someone deleted the state object from the S3 bucket. `terraform plan` now wants to create 140 resources that already exist.IntermediateState is gone and the bucket had no versioning. How do you recover a production stack?Advanced`Error: Failed to load state` followed by a JSON error like `invalid character '}' looking for beginning of object key string`.IntermediateThe plan prints `Note: Objects have changed outside of Terraform` and lists a security group with an extra ingress rule.BeginnerEvery plan wants to change `desired_capacity` on an Auto Scaling group back to 2, though autoscaling has raised it to 6.BeginnerA resource was deleted manually in the console. The plan wants to create it, and an apply fails because a dependent resource still references the old ID.Intermediate