Has anyone found a way to do something like this?
Assume I have 3 public subnets with 3 nat gateways deployed across them.
Note the added ${count.index} within the aws_nat_gateway subnet_id which throws an error
data "aws_availability_zones" "availability_zones" {}
data "aws_subnet" "public_subnets" {
count = "${length(data.aws_availability_zones.availability_zones.names)}"
tags {
Name = "public-subnet-${count.index}"
}
}
data "aws_nat_gateway" "natg" {
count = "${length(data.aws_availability_zones.availability_zones.names)}"
subnet_id = "${data.aws_subnet.public_subnets.${count.index}.id}"
tags {
Name = "public-subnet-nat-${count.index}"
}
}
You should use ${data.aws_subnet.public_subnets.*.id[count.index]}
instead. This uses the splat
operator to return the list of the iterated subnets and then indexes based on the current count index.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.