Lesson 2 of 4 · Resource Relationships & Dependencies
Implicit dependencies
Terraform constructs a dependency graph from expressions. When a resource reads another resource’s ID, ARN, or name, Terraform normally knows it must create the first resource before the second.
Example
resource "aws_internet_gateway" "igw" {
vpc_id = aws_vpc.main.id
}Step by step
- Use the actual value another resource needs.
- Run terraform plan to inspect the order.
- Keep references close to the attribute they configure.
- Prefer this direct style over manual ordering.
Common mistakes to avoid
- Adding depends_on when a direct ID reference already exists.
- Assuming declaration order controls creation order.