Skip to main content
What actually happens when you run a Terraform plan or apply? Behind every terraform plan and terraform apply is a dependency graph — the resource graph — that Terraform constructs from your configuration. This graph determines the order and parallelism of operations, and understanding it explains much of Terraform’s behavior and helps with the HashiCorp Certified: Terraform Associate exam. This lesson explains:
  • How Terraform builds the resource graph
  • The difference between implicit and explicit dependencies
  • How Terraform schedules work (parallelism)
  • When to use depends_on
This topic is also referenced in the HashiCorp Certified: Terraform Associate 004 certification content.

How Terraform builds the dependency graph

Terraform reads your configuration and constructs an internal dependency graph from attribute references between resources. It does not execute resources in the order they appear in files — it uses relationships inferred from references to compute the correct execution order. Key results:
  • Resource order in files does not dictate creation order.
  • Splitting resources into multiple files does not change the graph or execution order.
  • References such as aws_subnet.example.vpc_id = aws_vpc.example.id create implicit dependencies.
  1. Resource order in your Terraform files does not determine creation order.
A presentation slide titled "Resource Graph" that explains how Terraform builds a dependency graph during a plan, with bullet points summarizing key ideas. On the right is a purple-framed photo of a laptop keyboard and a "Key Concept" text box.
Terraform parses all resources and builds the graph from references between them. The graph, not file order, defines what gets created first.
  1. The resource graph enables parallel execution. If two resources have no dependency between them, Terraform can create them concurrently. This parallelism greatly reduces total apply time for large deployments.
  2. The graph shows when you need explicit dependencies (depends_on). Most dependencies are implicit and inferred from attribute references. Use depends_on only when Terraform cannot infer ordering from attributes.

Dependencies: implicit vs explicit

Terraform recognizes two dependency types: implicit and explicit.

Implicit dependencies

Implicit dependencies are automatically created when one resource refers to another resource’s attributes. Terraform infers the ordering from such references. Example topology (conceptual): one virtual network at the top → three subnets in the middle → three VMs at the bottom. Each subnet references the virtual network, and each VM references a subnet. Terraform infers the ordering: virtual network → subnets → VMs. In HCL, an implicit dependency looks like this:
Because aws_subnet.example references aws_vpc.example.id and aws_instance.web references aws_subnet.example.id, Terraform automatically orders creation accordingly.
A presentation slide titled "Dependencies" showing a purple diagram of a Virtual Network at the top with Subnet boxes and VM boxes below connected by arrows. The right side contains bullet points explaining implicit and explicit Terraform dependencies.

Explicit dependencies

Use explicit dependencies when Terraform cannot infer ordering from attribute references. Add the depends_on meta-argument to force an ordering. Example: if the web server must be created after a database for reasons not captured by attributes, use:
Explicit depends_on is useful only when ordering cannot be inferred automatically from resource attributes. Overusing explicit dependencies reduces Terraform’s ability to parallelize operations.

How Terraform walks the dependency graph (parallel execution)

Terraform traverses the graph and schedules resource operations as soon as their dependencies are satisfied. When multiple resources are ready, Terraform processes them concurrently, which increases throughput for large deployments. Default parallelism is 10 concurrent operations. You can override this with the -parallelism flag on plan, apply, or destroy:
When to change parallelism:
  • Lower parallelism if the provider API rate-limits requests.
  • Set to 1 for debugging or when strictly sequential operations are required.
  • Keep the default (10) for most real-world uses.

Quick reference for the exam and practical use

Additional resources

Summary: Terraform’s resource graph is what determines ordering and concurrency for plan and apply. Understand implicit references first and reserve depends_on for edge cases. Use parallelism wisely based on provider limits and debugging needs.

Watch Video