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

  1. Use the actual value another resource needs.
  2. Run terraform plan to inspect the order.
  3. Keep references close to the attribute they configure.
  4. 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.