← Lessons/Dependencies & the Resource Graph
← Dependencies & the Resource Graph

Add an implicit dependency

Learn

Implicit dependencies (references) — the default

When one resource references another's attribute, Terraform infers that it must come second:

resource "demo_server" "web" {
  network_id = demo_network.main.id   # ← reference
}

Because web uses demo_network.main.id, Terraform knows the network must exist first. You didn't declare an order — the reference is the order:

demo_network.main: Creating...
demo_network.main: Creation complete
demo_server.web: Creating...
demo_server.web: Creation complete

It has to be: the network's id doesn't exist until the network does. This is the idiomatic way to sequence resources, and it's self-documenting: the dependency is visible right where the value is used.

Attach the server to the network: set network_id = demo_network.main.id on demo_server.web. That reference is an implicit dependency — Terraform now knows the network must exist first. Switch to apply and run it; the network is created before the server, guaranteed by the reference.

Loading...

State Inspector

State

Terraform's memory

empty — nothing here yet

Real Infrastructure

the actual world

empty — nothing here yet