Data Sources
Cheat sheet · https://pcornel.dk/topic.php?topic=5444
Answer
Terraform/OpenTofu data sources read external information during evaluation and feed values into the graph without owning those source objects.
Remember
- Data read success ≠ source object stability; values can change between runs and may introduce unknown or environment-dependent plan behavior.
- 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 <<< 'data.<type>.<n>.id'— inspect- Permissions for data reads — access
- Stable data sources — noise-free plans
Verify in this order
data block → read → values
Where it usually breaks
Data read success ≠ source object stability; values can change between runs and may introduce unknown or environment-dependent plan behavior. 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.
Data Sources IaC proof-boundary map
| Boundary | Healthy evidence | Suspicious evidence |
|---|---|---|
| Definition / inputs | Exact revision, toolchain and effective inputs are reproducible | Different runner/version/input context changes evaluation |
| State / planning | Correct backend/state/lock, fresh reads and reviewed graph/plan | Wrong state/workspace, stale reads, unsafe replacement/destroy or missing lock |
| Execution | Expected provider/API operations complete and state persists | Partial apply, auth/API error, ambiguous retry or failed state write |
| Target proof | Independent read-back plus fresh plan confirm intended convergence | Engine 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=5444