安全组之间的Terraform循环依赖关系

安全组之间的Terraform循环依赖关系,terraform,amazon-ecs,aws-application-load-balancer,Terraform,Amazon Ecs,Aws Application Load Balancer,我在ECS前面有一个设置:ALB。我有一个ecs模块和一个alb模块: ALB_sg的ALB的出口规则: egress { description = "Traffic from ALB to ECS" from_port = 80 to_port = 80 protocol = "tcp" security_groups = [var.ecs_sg] //com

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

  egress {
    description     = "Traffic from ALB to ECS"
    from_port       = 80
    to_port         = 80
    protocol        = "tcp"
    security_groups = [var.ecs_sg] //comes from output from ecs stack
  } 
现在在ECS中,我为其安全组提供了类似的功能(
ECS\u sg

现在我有一些错误:

│ 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)

如何解决这个问题?谢谢

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

│ 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)