I am trying to use the count.index variable within a resource to use resources already created. I am using "${concat("aws_subnet.public." , count.index, ".id}")}" as the subnet_id for a resource. However it doesn't really work very well. Since the interpolation of that is a string and not a reference to the resource's real id.
resource "aws_subnet" "public" {
cidr_block = "${concat(var.vpc_cidr_block_base, ".", count.index ,".0/24")}"
availability_zone = "${concat(var.region, lookup(var.vpc_availability_zone, concat("zone_", count.index)))}"
count = "${var.zone_count}"
depends_on = ["aws_vpc.default", "aws_internet_gateway.default"]
}
# Routing table for public subnets
resource "aws_route_table" "public" {
route {
}
depends_on = ["aws_vpc.default", "aws_internet_gateway.default"]
}
resource "aws_route_table_association" "public" {
subnet_id = "${concat("aws_subnet.public." , count.index, ".id}")}"
count = "${var.zone_count}"
depends_on = ["aws_vpc.default", "aws_internet_gateway.default"]
}