Lesson 3 of 4 ยท Resource Relationships & Dependencies

When to use depends_on

Use depends_on for a real ordering relationship that is not represented by a value reference. It should be a specific explanation of a hidden dependency, not a general error-fixing tool.

Example

resource "aws_instance" "app" {
  ami           = "ami-0123456789abcdef0"
  instance_type = "t3.micro"

  depends_on = [aws_iam_role_policy.app]
}

Step by step

  1. First look for a direct value reference.
  2. Identify the hidden prerequisite.
  3. Reference the resource address in depends_on.
  4. Keep the list as small as possible.

Common mistakes to avoid

  • Depending on a variable instead of a resource.
  • Using depends_on to conceal an invalid reference.