Loading

Quipoin Menu

Learn • Practice • Grow

terraform / Troubleshooting
tutorial

Troubleshooting

Even with correct configurations, things can go wrong. This chapter covers common Terraform errors and how to resolve them.

Common Errors and Solutions

  • Provider credentials missing: Set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY or run aws configure.
  • Resource already exists: Import it into state using terraform import.
  • State lock error: Another process is holding the lock. Wait or use terraform force-unlock (with caution).
  • Invalid AMI ID: Verify the AMI exists in your region. Use aws ec2 describe-images or data source.
  • Missing variables: Ensure all required variables are defined (no default). Terraform will prompt or error.
  • Syntax errors: Run terraform validate to catch HCL errors.

Troubleshooting Commands

  • terraform validate – checks syntax and consistency.
  • terraform plan -out=tfplan – save plan for review.
  • terraform state list – show resources in state.
  • terraform state show <resource> – inspect a resource.
  • terraform providers – show provider versions.
  • terraform version – check Terraform version (updates matter).

Debugging with TF_LOG

Enable detailed logging:
export TF_LOG=DEBUG
terraform apply
To log to a file:
export TF_LOG_PATH=terraform.log
terraform plan
Set log level: TRACE, DEBUG, INFO, WARN, ERROR.

Importing Existing Resources

If a resource was created outside Terraform, you can import it into state.
terraform import aws_instance.web i-1234567890abcdef0
Then write the configuration manually to match.

Checking Provider Version Compatibility

Use terraform providers lock to lock provider versions. Mismatched versions can cause unexpected behavior.


Two Minute Drill
  • Run terraform validate to catch syntax errors.
  • Use terraform import to bring existing resources into state.
  • Set TF_LOG=DEBUG for detailed logging.
  • Check state with terraform state list and state show.
  • Lock provider versions to avoid drift.

Need more clarification?

Drop us an email at career@quipoinfotech.com