Table of Contents

The Error

Error: Error locking state: HTTP remote state endpoint returned 409

What Causes This

The HTTP-based state backend returned 409 Conflict because another run is in progress for this workspace.

How to Fix It

Solution 1: Cancel Active Run (Terraform Cloud)

# Via UI: Workspace > Runs > Cancel
# Via API:
curl -X POST -H "Authorization: Bearer $TFC_TOKEN" \
  "https://app.terraform.io/api/v2/runs/RUN_ID/actions/cancel"

Solution 2: Wait and Retry

sleep 60
terraform apply

Solution 3: Unlock Workspace

curl -X POST -H "Authorization: Bearer $TFC_TOKEN" \
  "https://app.terraform.io/api/v2/workspaces/$WS_ID/actions/unlock"

Prevention Tips

  1. Pin provider versions — avoid surprise breaking changes
  2. Use CI/CD — catch errors before they hit production
  3. Test with terraform plan — always review before applying
  4. Keep Terraform updated — newer versions have better error messages
  5. Use terraform validate — catches syntax errors early

Hands-On Courses

Conclusion

This error is common and fixable. Follow the solutions above, and check our Terraform course for hands-on training that covers real-world troubleshooting scenarios.