Ad space (banner)
AD

Got the fundamentals? A structured Terraform course is a fast way to level up.

Find Terraform courses on Udemy

Affiliate link. Costs you nothing extra.

Lesson 32 / 37

What Is depends_on?

Terraform usually works out the order for itself, from the references between resources. depends_on is for the cases where it can't see the relationship.

When resource B references an attribute of resource A, Terraform knows A comes first. When the dependency is real but invisible in the configuration, you state it explicitly.

Writing depends_on = [aws_instance.web] forces that ordering even with no attribute reference between them.

A common stumble is adding depends_on everywhere out of caution, which serialises work that could have run in parallel and slows every apply.

In real work, it is reserved for genuinely hidden dependencies — an IAM policy that must exist before the thing using it, for example.

Terraform
Try it (type this into the pseudo terminal)
terraform plan

🧑‍💻 You can type this command into the Terraform pseudo terminal to try it yourself (this page itself has no interactive terminal).

Ad space (banner)
Ad space (in-article)