Pcornel
Automation · Terraform / OpenTofu

Drift

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

Back to the Topic

Answer

Terraform/OpenTofu drift appears when provider refresh/read shows the remote object differs from the last managed expectation or current configuration.

Remember

  • Drift detected ≠ remediation decided; some out-of-band changes are intentional and require ownership review before apply.
  • 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

  • terraform plan -refresh-only — drift
  • Scheduled drift job — detection
  • Restrict manual console changes — prevention

Verify in this order

real infra → refresh → drift report

Where it usually breaks

Drift detected ≠ remediation decided; some out-of-band changes are intentional and require ownership review before apply. The proof boundary ends where provider/state evidence stops and target-domain acceptance begins.

Configuration/input → graph/state refresh → plan → provider API request → provider terminal result → resource read-back → effective service state → workload. Preserve at least three independent checks: prerequisite/interface or identity/transport state; the owning control/service/policy state; then effective data-plane, backend or workload state. A healthy upstream boundary does not prove the downstream consumer or return path.

Drift 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=5462

Confirmation

Confirm action

Continue?