terraform plan and how Terraform determines the order for creating, updating, or destroying resources. Terraform automatically constructs a dependency graph from your configuration; this graph drives how an execution plan is generated and how operations are ordered and parallelized. This is a core concept for using Terraform effectively and is explicitly tested on the HashiCorp Certified: Terraform Associate exam.
The resource graph is built from references between resources and data sources. Understanding it clarifies Terraform’s execution order, parallelism, and why file order doesn’t control deployment order.
- Terraform builds a dependency graph from references between resources and data sources.
- The graph (not file order) determines the execution order.
- Resources without mutual dependencies can run in parallel, improving performance.
- Use
depends_ononly when Terraform cannot infer an ordering from configuration references.

- Implicit dependencies
- Inferred automatically from attribute and data source references in your configuration.
- Example: if a subnet references a VPC’s ID, Terraform knows the VPC must be created before the subnet.
aws_subnet.subnet_a implicitly depends on aws_vpc.main because of the aws_vpc.main.id reference.
- Explicit dependencies
- Declared using
depends_onwhen Terraform cannot infer an ordering (for example, when resources are related but have no direct attribute references). - Use explicit dependencies sparingly; most ordering should come from implicit references.
- Declared using
aws_instance.web resource explicitly depends on aws_db_instance.db even though there is no attribute reference linking them.

| Dependency type | How Terraform discovers it | When to use | Example |
|---|---|---|---|
| Implicit | Inferred from attribute references and data sources | Default; use whenever possible | vpc_id = aws_vpc.main.id |
| Explicit | Declared manually with depends_on | When there is an ordering requirement Terraform can’t infer | depends_on = [aws_db_instance.db] |
-parallelism flag on plan, apply, and destroy to accommodate API rate limits or to debug ordering behavior.
Example usage:
Remember: Terraform’s default parallelism is 10 operations. Adjust with
-parallelism=<N> on CLI commands when you need to limit concurrent API calls or force more sequential behavior.- Prefer implicit dependencies (attribute references) over
depends_on. - Keep related resources together for readability, but split into files or modules for organization — Terraform will still infer dependencies correctly.
- Use
-parallelismonly when necessary (rate limits, debugging, or provider-specific constraints). - Inspect
terraform planoutput to verify inferred ordering beforeapply.
- Terraform automatically builds and walks a dependency graph from references in your configuration.
- File ordering does not control execution order — dependency references do.
- Use
depends_ononly when Terraform cannot infer the required ordering from references. - Terraform executes resources in parallel where possible; default concurrency is 10, adjustable via
-parallelism. - A clear understanding of the resource graph explains how
terraform plangenerates an execution plan and why operations run in a particular order.
- Terraform Documentation — Resource Graph and Dependencies
- HashiCorp Learn — Graphs and State
- HashiCorp Certified: Terraform Associate Exam Guide