我正在尝试从 VPC 模块中获取可用区并将其传递给 ELB 资源参数。如何指定托管我希望 ELB 发送流量的两个公有子网的 AZ?
这是我得到的错误:
Error: Error creating ELB: ValidationError: Invalid Availability Zone: module.network_stack.availability_zones[*]
│ status code: 400, request id: f9e5fc9b-d158-443f-8032-8706578f3b0c
│
│ with aws_elb.web_elb,
│ on main.tf line 55, in resource "aws_elb" "web_elb":
│ 55: resource "aws_elb" "web_elb" {
这是 GitHub 存储库的链接:
https://github.com/cdziachan/Terraform-HA-Web-App
我特别从 Main.tf 中的这个 ELB 资源中得到了错误:
resource "aws_elb" "web_elb" {
name = "web-elb"
availability_zones = ["module.network_stack.availability_zones[*]"]
security_groups = [module.network_stack.web_sg_id]
listener {
instance_port = 80
instance_protocol = "http"
lb_port = 80
lb_protocol = "http"
}
health_check {
healthy_threshold = 2
unhealthy_threshold = 2
timeout = 10
target = "HTTP:80/"
interval = 30
}
}
来自 VPC 模块的 Outputs.tf:
output "availability_zones" {
value = data.aws_availability_zones.available[*].names
}
VPC 模块中 Main.tf 的公共子网:
resource "aws_subnet" "public_subnets" {
count = length(var.public_subnet_cidrs)
vpc_id = data.aws_vpc.prod.id
cidr_block = var.public_subnet_cidrs[count.index]
availability_zone = data.aws_availability_zones.available.names[count.index]
map_public_ip_on_launch = true
tags = merge(var.tags, {
Name = "Public Subnet ${count.index + 1}"
Region = "${data.aws_region.current.description}"
Env = "${var.env}"
VPC = "${data.aws_vpc.prod.id}"
})
}