Pcornel
Automation · Terraform / OpenTofu

Terraform / OpenTofu Troubleshooting

Cheat sheet · https://pcornel.dk/topic.php?topic=5463

Back to the Topic

Answer

Terraform/OpenTofu troubleshooting isolates failures across binary/version, HCL evaluation, init/dependency resolution, backend/state/locking, provider credentials/schema, graph/plan and target API execution.

Remember

  • CLI error location ≠ root-cause boundary; a provider, backend or graph symptom can be caused by earlier version, state, credential or selection errors.
  • Terraform/OpenTofu command success ≠ target workload health; provider operations and application acceptance are separate proof boundaries.
  • The same repository ≠ same run when binary, provider/module versions, backend/workspace, variables, credentials or lock selections differ.
  • Treat Terraform and OpenTofu as separate implementations: verify behavior against the pinned tool and dependency versions rather than assuming interchangeability.

First checks

  • TF_LOG=DEBUG terraform plan 2> tf.log — debug
  • terraform providers — version issues
  • terraform state list | grep <addr> — state presence

Commands

terraform validate
Check Terraform configuration syntax and internal consistency.

Verify in this order

init → plan → apply → error

Where it usually breaks

CLI error location ≠ root-cause boundary; a provider, backend or graph symptom can be caused by earlier version, state, credential or selection errors. The proof boundary ends where provider/state evidence stops and target-domain acceptance begins.

Terraform / OpenTofu Troubleshooting IaC proof-boundary map

BoundaryHealthy evidenceSuspicious evidence
Definition / inputsExact revision, toolchain and effective inputs are reproducibleDifferent runner/version/input context changes evaluation
State / planningCorrect backend/state/lock, fresh reads and reviewed graph/planWrong state/workspace, stale reads, unsafe replacement/destroy or missing lock
ExecutionExpected provider/API operations complete and state persistsPartial apply, auth/API error, ambiguous retry or failed state write
Target proofIndependent read-back plus fresh plan confirm intended convergenceEngine success treated as workload acceptance or drift remains unexplained

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=5463

Confirmation

Confirm action

Continue?