Pcornel
Automation · Terraform / OpenTofu

Local Values

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

Back to the Topic

Answer

Local values name derived expressions inside a module to simplify reuse and make evaluated relationships explicit.

Remember

  • Local value ≠ external input or persisted state; it is recalculated from current expression dependencies.
  • 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 console <<< 'local.<n>' — value
  • locals for computed/repeated values — DRY
  • Avoid overly complex locals — readability

Verify in this order

expressions → locals → used in resources

Where it usually breaks

Local value ≠ external input or persisted state; it is recalculated from current expression dependencies. 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.

Local Values 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=5446

Confirmation

Confirm action

Continue?