Terraform compiles your config into a DAG — a dependency graph. Every
reference is an edge: subnet uses aws_vpc.main.id, so the VPC
goes first. Apply walks the graph, running each node as soon as its dependencies finish —
up to 10 at once by default. File order, alphabetical order, the order you wrote things:
all irrelevant. Only the graph decides.
Implicit — any expression reference. This is 95% of your graph and it's free.
Explicit — depends_on, for dependencies the config can't see: the classic
is an app instance that needs an IAM role's policy attachment to exist before boot, but only
references the role itself.
Code smell: depends_on where a reference would do. It coarsens the graph and hides
the real relationship from the next reader.
That -/+ from lesson 0001? Internally it's a destroy node + create node,
because destroy order is the reverse of create order. Default sequence:
destroy old → create new — which is a downtime window. lifecycle {
create_before_destroy = true } flips it: new first, then old — zero gap, but old and new
must coexist, which unique-name resources can't do. That's why it's opt-in.
terraform_data resources where C references B's output and B references A's. Apply and watch the strict A→B→C ordering.terraform graph on any real config; paste the DOT output into an online Graphviz viewer and find your longest dependency chain.terraform state list: the first instance is there. No rollback.