当尝试通过 terraform 在 AWS 中创建 elb(经典负载均衡器)时,我发送了从另一个模块创建的公共子网 ID 列表。在本例中,我有 4 个子网,跨越 3 个可用区。当我尝试运行 terraform 时,我有来自 az-1a 的 2 个子网,我收到一条错误消息same az can't be used twice for ELB
resource "aws_elb" "loadbalancer" {
name = "loadbalancer-terraform"
subnets = var.public_subnets
listener {
instance_port = 80
instance_protocol = "http"
lb_port = 80
lb_protocol = "http"
}
depends_on = [aws_autoscaling_group.private_ec2]
}
Run Code Online (Sandbox Code Playgroud)
有什么方法可以从给定列表中选择子网,这样我只能从不同的 AZ 获取子网 id。
subnetid1 -- az1-a
subnetid2 -- az1-b
subnetid3 -- az1-c
subnetid4 -- az1-a
Run Code Online (Sandbox Code Playgroud)
现在我需要获得子网 1,2 和 3 或子网 2,3 和 4 的输出。