我正在尝试将ELB分配给新VPC中的公共子网:
resource "aws_subnet" "public" {
vpc_id = "${aws_vpc.dev-vpc.id}"
cidr_block = "${var.public_subnet}"
availability_zone = "${var.aws_region}a"
map_public_ip_on_launch = false
tags {
Name = "public"
Environment = "${var.environment}"
}
}
我收到以下错误:
aws_elb.terraformelb: : invalid or unknown key: subnet_id
如果删除子网参数,则会将ELB分配给默认VPC。
这是我的terraform elb代码:
resource "aws_elb" "terraformelb" {
subnet_id = "${aws_subnet.public.id}"
security_groups = ["${aws_security_group.terraformelb-sg.id}"]
cross_zone_load_balancing = "true"
idle_timeout = "60"
connection_draining = "true"
connection_draining_timeout = "300"
tags = {
Name = "${var.environment}-${var.environment_name}-elb"
Env_Name = "${var.environment}-${var.environment_name}"
Environment = "${var.environment}"
Version = "${var.version}"
}
listener {
lb_port = 80
lb_protocol = "http"
instance_port = "${var.server_port}"
instance_protocol = "http"
}
health_check {
healthy_threshold = "10"
unhealthy_threshold = "2"
timeout = "2"
interval = "5"
target = "HTTP:${var.server_port}/"
}
}
请告诉我如何将ELB分配给子网。
谢谢,
答案 0 :(得分:1)
它是子网而不是subnet_id =“$ {aws_subnet.public.id}”
答案 1 :(得分:0)
子网是您想要的参数。
子网 - (对于VPC ELB是必需的)要附加到的子网ID列表 ELB。
subnets = ["${aws_subnet.public.id}"]
此外,VPC ELB不需要availability_zones,它与所提供的子网有关。
availability_zones - (对于EC2经典ELB是必需的)AZ来自 提供交通。
https://www.terraform.io/docs/providers/aws/r/elb.html#subnets
如果您将cross_zone_load_balancing
设置为" true"
在要启动的每个可用区中创建子网 实例。根据您的应用程序,您可以启动您的 公共子网,私有子网或其组合中的实例 公共和私人子网。公有子网具有到Internet的路由 网关。请注意,默认VPC每个都有一个公有子网 可用区默认为。
https://docs.aws.amazon.com/elasticloadbalancing/latest/classic/elb-backend-instances.html