Interview Prep/Terraform/Dependencies, Cycles and Providers

`Error: Cycle: aws_security_group.app, aws_security_group.db`.

BeginnerTroubleshootingDependencies, Cycles and Providers
Answer

Likely causes → Each group's inline ingress references the other group's ID, so neither can be created first.

Diagnose →

terraform graph -type=plan | dot -Tsvg > graph.svg

Look for the two nodes pointing at each other.

Fix → Create both groups without inline rules, then add rules as separate resources:

resource "aws_vpc_security_group_ingress_rule" "db_from_app" {
  security_group_id            = aws_security_group.db.id
  referenced_security_group_id = aws_security_group.app.id
  from_port                    = 5432
  to_port                      = 5432
  ip_protocol                  = "tcp"
}

Prevent → Standardize on standalone rule resources for all security groups.

All Terraform questions Roadmap: Terraform

More on Dependencies, Cycles and Providers