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
- First look for a direct value reference.
- Identify the hidden prerequisite.
- Reference the resource address in depends_on.
- 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.