I have created couple of subnets using the resource block below.
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
tags {
Name = "${var.private}-${format("%01d", count.index + 1)}"
Environment = "${terraform.workspace}"
}
}
After which I created eip's, nat's, private route table, added route to the private route table and lastly, when I try to associate the private route table to private* subnets terraform works partially i.e. out of 4 subnets only 2 private subnets are associated with the private route table.
resource "aws_route_table_association" "private-subnet-association" {
subnet_id = "${element(aws_subnet.private.*.id, count.index)}"
route_table_id = "${aws_vpc.vpcname.private_route_table.id}"
}
What do I have to change to apply the association to all the private subnets.
subnet_id = "${element(aws_subnet.private*.?.id, count.index)}"