Answer the question
In order to leave comments, you need to log in
How to correctly set the id of dynamically created subnets in elb terraform?
How to correctly write the id of the created subnets in elb terraform?
data "aws_availability_zones" "available" {}
locals {
az_names = data.aws_availability_zones.available.names
}
resource "aws_subnet" "wpl_public_subnet" {
for_each = { for index, az_name in local.az_names : index => az_name }
vpc_id = aws_vpc.wpl_vpc.id
cidr_block = cidrsubnet(var.vpc_cidr, 8, each.key + 10)
availability_zone = local.az_names[each.key]
map_public_ip_on_launch = true
tags = {
Name = "WPL-PublicSubnet"
CreatedBy = var.created_by
}
}
resource "aws_elb" "wpl_elb" {
name = "terraform-elb"
security_groups = [aws_security_group.wpl_sg.id]
subnets = [for_each aws_subnet.wpl_public_subnet : each.value.id]
listener {
instance_port = 80
instance_protocol = "http"
lb_port = 80
lb_protocol = "http"
}
cross_zone_load_balancing = true
idle_timeout = 400
connection_draining = true
connection_draining_timeout = 400
tags = {
Name = "WPL-ELB"
}
}
subnets = [aws_subnet.wpl_public_subnet[*].id]
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question