Terraform · Infrastructure as code

When should you use depends_on?

Mediumdependency orderingdependency graphexplicit dependenciesUpdated Oct 2026
Quiz this track

Short answer

Terraform infers dependencies from references. depends_on adds an explicit edge when no value is passed, but overusing it serialises work and hides real data flow.

The dependency graph is built from expressions. If a resource argument references another resource's attribute, the edge is implicit and precise. depends_on exists for cases where ordering matters but no value is exchanged, such as an IAM policy that must exist before an application starts.

hcl
resource "aws_s3_bucket" "logs" {
  bucket = "acme-logs"
}

resource "aws_s3_bucket_policy" "logs" {
  bucket = aws_s3_bucket.logs.id
  policy = data.aws_iam_policy_document.logs.json

  depends_on = [aws_s3_bucket_public_access_block.logs]
}
The bucket reference is implicit. depends_on covers the block that must be in place first.

Implicit versus explicit

  • Implicit: an expression uses another resource's attribute
  • Explicit: depends_on names an address without passing a value
  • Module depends_on applies to every resource in the module
  • Overuse creates long serial chains and slower plans and applies

depends_on cannot guarantee application readiness. It only orders Terraform operations. If a service must be healthy before a migration runs, use a health check or a provisioning step that waits on the actual condition, not a graph edge.

If you find yourself adding depends_on everywhere, the real problem is usually a missing output or a module boundary that does not expose the dependency.

Follow-ups you should expect

Interviewers use these to check whether the first answer was understanding or memorisation.

  1. 1What is the difference between implicit and explicit dependencies?
  2. 2What does depends_on on a module affect?
  3. 3Why is overusing depends_on a problem?
  4. 4Can depends_on guarantee an application is ready?

Say it in the interview

Terraform already derives dependencies from references, so I use depends_on only when ordering matters but no value is exchanged. On a module it applies to every resource inside, which can serialise a lot of work. I avoid using it as a readiness mechanism, because it orders Terraform operations, not application health. If I need many depends_on entries, I look for a missing output or a bad module boundary.

Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.

Related questions

Reading is step one

Now say it out loud.

Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live Terraform mock interview and get scored feedback on depth, clarity and confidence.