I\'m trying to create multiple subnets from one resource block and I get the following error
Error: aws_subnet.private: cidr_block must be a single v
private_subnet
is a list, so you should pick a single element, e.g.
cidr_block = "${element(var.private_subnet,count.index)}"
You have to create multiple aws_subnet
resources by utilitizing the count
argument to create one resource for each entry in your var.private_subnet
list:
resource "aws_subnet" "private" {
count = "${length(var.private_subnet)}"
vpc_id = "${aws_vpc.vpcname.id}"
cidr_block = "${var.private_subnet[count.index]}"
availability_zone = "${data.aws_availability_zones.available.names[count.index]}"
map_public_ip_on_launch = false
}
This expands the single aws_subnet
resource into two, each with slightly different values based on the enumeration of count
when each resource block is evaluated by terraform.