Two resources reference each other
CommonThe classic case is two security groups whose inline rules allow traffic from each other: each group needs the other's ID before it can be created.
Confirm
terraform validate
Exactly two resource names in the cycle
Fix
- Create the groups without rules that point at each other, and put each rule in its own resource that references both groups. For AWS, the provider docs recommend aws_vpc_security_group_ingress_rule and aws_vpc_security_group_egress_rule over inline rules anyway.
resource "aws_vpc_security_group_ingress_rule" "db_from_web" {
security_group_id = aws_security_group.db.id
referenced_security_group_id = aws_security_group.web.id
ip_protocol = "tcp"
from_port = 5432
to_port = 5432
}The same shape with terraform_data stand-ins validated on Terraform 1.14.0; argument names from the AWS provider docs, not run against AWS here.