Lesson 4 of 4 ยท Debugging Terraform

Dependency mistakes

A configuration can parse correctly while still describing impossible or incorrect relationships. Check whether each reference points to a declared resource, whether a resource refers to itself, and whether two resources require each other before either can exist.

Example

resource "aws_instance" "web" {
  ami       = "ami-0123456789abcdef0"
  user_data = aws_instance.web.private_ip # self reference
}

Step by step

  1. Draw the relationship as an arrow.
  2. Check whether the target exists.
  3. Check whether the arrow points back to the same resource.
  4. Break cycles before adding more resources.

Common mistakes to avoid

  • Mistaking a valid runtime connection for a Terraform creation dependency.
  • Ignoring hidden references inside locals.