`Error: Failed to load state` followed by a JSON error like `invalid character '}' looking for beginning of object key string`.
IntermediateTroubleshootingLost, Corrupted and Drifted State
Answer
Likely causes → Someone edited state by hand (trailing comma, bad merge) and uploaded it, or a truncated write from an interrupted upload.
Diagnose →
terraform state pull > broken.json 2>/dev/null || aws s3 cp s3://acme-tfstate/prod/app/terraform.tfstate broken.json
jq . broken.json > /dev/null # shows the line of the syntax error
Fix → Restore the previous S3 version. If no good version exists, fix the JSON carefully, bump serial by one, and terraform state push.
Prevent → Never hand-edit state. Use terraform state mv/rm, moved, removed and import blocks; they validate and back up.
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?AdvancedThe 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`terraform plan -refresh-only` shows drift, and you apply it. The next normal plan still wants to revert the change. Why?Intermediate