Corrupted local state — JSON parse error in state file
Error: Error loading state: SyntaxError: JSON input
Focused incident mode — strips away everything but this runbook.
Symptoms
- Error: Error loading state: SyntaxError: JSON input
- terraform plan fails with state parse error
- Local state file is corrupted or truncated
Never manually edit terraform.tfstate — use terraform state commands. Always use remote backends for team environments.
Evidence to grab
Collect these artifacts before you change anything — they prove (or rule out) each cause.
Parse error output
terraform plan 2>&1 | head -10State file integrity check
python3 -c 'import json; json.load(open("terraform.tfstate"))' 2>&1
Diagnostic flow
Run the steps in order, marking each claim confirmed or refuted. The evidence you gather feeds the ranked causes below.
Guided decision tree is ready.
Steps with commands, expected output, and pass/fail branches.
Ranked root causes
Evidence checklist
- State file is truncated or has partial JSON
- Process was killed during terraform apply
Confirm before fixing
python3 -c 'import json; json.load(open("terraform.tfstate"))' 2>&1Validate the state file JSON
Fix
cp terraform.tfstate.backup terraform.tfstate && terraform planRestore from the most recent backup
Resolution runbook
Apply from top to bottom after the cause is confirmed. Review every command before running it — risk tags are shown on each.
python3 -c 'import json; json.load(open("terraform.tfstate"))' 2>&1Validate the state file JSON
ls -la terraform.tfstate* backup/Find available backups
cp terraform.tfstate.backup terraform.tfstateRestore from backup
terraform state pull > terraform.tfstate.restoredPull remote state as fallback recovery
terraform planVerify state is restored and functional
Prevention
- Use remote backends (S3, GCS, Terraform Cloud) instead of local state.
- Enable state file versioning on the remote backend.
- Use CI pipeline locks to prevent concurrent applies.
- Keep local state backups in .gitignore but monitor state file health.
Related runbooks
Same stack, same failure family — worth a skim.
terraform plan shows everything will be created (no existing resources in state)
Backend initialization required: please run "terraform init"
Error: Unable to find matching value for tag
Commands marked READ CHANGE DESTRUCTIVE — never run DESTRUCTIVE commands against production data you cannot restore. Copy → verify → execute.