depends_on is a Terraform meta-argument that creates explicit ordering between resources. Terraform usually determines ordering automatically via implicit dependencies when one resource references another’s attributes. For example, a subnet that references a VPC ID creates an implicit dependency and Terraform ensures the VPC is created first.
But when Terraform cannot infer the relationship from resource attributes — for instance, when one resource must be fully ready before another starts — you should use depends_on to enforce ordering and prevent race conditions.
Key benefits of depends_on:
- Forces a specific creation order in Terraform plans and applies.
- Prevents race conditions when resources must be fully provisioned before others start.
- Ensures downstream resources that perform startup actions (migrations, initializations) have their upstream dependencies available.
- Use sparingly — prefer implicit dependencies where possible to retain parallelism and faster provisioning.

- Without
depends_on, Terraform may create both resources in parallel. If the web server expects the database to be available and initialized at startup (beyond just knowing its ID), you should enforce order withdepends_on.
depends_on prevents Terraform from creating the EC2 instance until the database resource has been created. Use this pattern when the application will try to connect or run migrations at startup and requires the database to be fully provisioned.
Prefer implicit dependencies (resource attribute references) when possible. Overusing
depends_on serializes execution and reduces Terraform’s ability to parallelize resource creation.- Implicit dependency: Terraform infers ordering from attribute references between resources.
- Explicit dependency: You use
depends_onwhen no attribute reference exists that would create the dependency automatically, but you still require a specific order.
depends_on explicitly enforces the order.
Only use
depends_on when necessary. If an attribute reference already expresses the dependency, prefer that implicit dependency. Misusing depends_on can hide configuration issues and slow down apply operations.depends_on — quick reference table
Related links and references
- Terraform Meta-Arguments: depends_on (docs)
- Terraform Concepts: Resource Dependencies
- AWS Provider Documentation
depends_ongives you explicit control over resource ordering when Terraform cannot infer dependencies from configuration.- Use it to avoid race conditions and to ensure resources that rely on completed provisioning are created in the correct order.
- Favor implicit dependencies where possible; reserve
depends_onfor cases where explicit ordering is truly required.