安全组之间的 Terraform 循环依赖

Den*_*boy 2 amazon-ecs terraform aws-application-load-balancer

我有一个设置:ALB 在 ECS 前面。我有一个 ecs 模块和一个 alb 模块:\nALB 的出口规则为alb_sg

\n
  egress {\n    description     = "Traffic from ALB to ECS"\n    from_port       = 80\n    to_port         = 80\n    protocol        = "tcp"\n    security_groups = [var.ecs_sg] //comes from output from ecs stack\n  } \n
Run Code Online (Sandbox Code Playgroud)\n

现在在 ECS 中,我的安全组有类似的内容 ( ecs_sg)

\n
  ingress {\n    description = "Allow ALB to ECS"\n    from_port   = 80\n    to_port     = 80\n    protocol    = "tcp"\n    security_groups = [var.alb_sg] //comes from output from alb stack\n  }\n
Run Code Online (Sandbox Code Playgroud)\n

现在我有一些错误:

\n
\xe2\x94\x82 Error: Cycle: module.ecs.var.alb_sg (expand), module.ecs.aws_security_group.ecs_sg, module.ecs.output.ecs_sg (expand), module.alb.var.ecs_sg (expand), module.alb.aws_security_group.alb_sg, module.alb.output.alb_sg (expand)\n
Run Code Online (Sandbox Code Playgroud)\n

如何解决这个问题?谢谢

\n

jel*_*csc 8

解决方案是分别创建 SG 和 SG 规则。您可以使用aws_security_group_rule资源定义 SG 规则。