Implicit and explicit dependencies
Draw the dependencies before reading the plan
A dependency tells Terraform that one operation relies on another. In this complete local example, report consumes the catalog output and is assumed to require a policy step as well. The policy resource is only a synthetic marker; it does not enforce any access control. All three resources use the built-in terraform_data type, so no external provider is required.
resource "terraform_data" "report" { input = terraform_data.catalog.output depends_on = [terraform_data.policy]}
resource "terraform_data" "catalog" { input = "books"}
resource "terraform_data" "policy" { input = "reviewed"}
output "report" { value = terraform_data.report.output}Although report appears first in the file, it cannot complete its creation before its prerequisites. In our diagrams, arrows point from a prerequisite toward its dependent: catalog → report and policy → report. This is a directed acyclic graph (DAG), meaning the arrows have direction and there is no circular path. Catalog and policy are independent; either can finish first. On a fresh successful apply the report output is expected to be books. The exact plan and execution were not observed.
Prefer an expression when a value flows between resources
The reference to terraform_data.catalog.output conveys both the needed value and its origin. Terraform derives an implicit dependency from it. Moving that reference into a local expression does not remove the relationship. In contrast, depends_on does not transfer a value: it communicates a prerequisite that is otherwise invisible to Terraform. Here policy is deliberately an illustrative hidden dependency. In a real configuration, add a comment explaining the missing behavioral relationship. Do not copy depends_on to every resource or substitute it for the value reference. Within this resource, the explicit list contains a resource address, not a string or dynamically computed list.
Inspect the graph and its limits
In a new disposable copy of lab-fixtures/dependency-graphs/dag, use the local-only setup described in the lab README. After initialization and validation, the following commands produce a DOT graph, then optionally a PNG using a separately installed Graphviz executable.
terraform graph > graph.dotdot -Tpng graph.dot -o graph.pngDOT is a graph description format. Terraform’s default graph is a simplified dependency view; it may draw arrows from dependent to prerequisite, opposite to our learning diagram. Check the relationship rather than matching our picture byte for byte. Operation graphs can contain internal nodes for provider configuration, module expansion, or separate create and destroy actions. Independent work may overlap; neither filename order nor a diagram fixes the exact schedule. The CLI parallelism option bounds concurrent graph processing, but setting it to one does not remove dependency cycles or guarantee readiness.
Connect modules through meaningful outputs
A module packages resources behind inputs and outputs. In this illustrative partial root configuration, assume the catalog child exports catalog_id and the report child accepts that input; those directories are not bundled for this snippet.
module "catalog" { source = "./catalog"}
module "report" { source = "./report" catalog_id = module.catalog.catalog_id}The output reference communicates the data dependency across the module boundary. Using a broad depends_on on the report module instead may delay unrelated work and make more planned values uncertain. If a hidden behavioral dependency really spans the modules, document it and scope it as narrowly as the design permits. A completed infrastructure operation still does not establish that an application is listening, healthy or authorized; verify that separately with an appropriate health test.
Practice reading graph order
For the three-node lab, write two legal schedules and one illegal schedule. A valid schedule never places report before either of its prerequisites. The independent graph checker uses only JSON node and edge lists; it is not Terraform and does not determine the real CLI execution order. Next, learn how circular requirements and values that become known later affect planning.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Implicit and explicit dependencies — knowledge check
Check graph order, cycle diagnosis and plan-time identity.
Which resource must report wait for in the DAG?
Which expression transfers a value as well as establishing a dependency?
What can happen to catalog and policy on a fresh apply?
What does a broad module depends_on risk?
What does successful dependency ordering prove?