有人找到做这种事情的方法吗?
假设我有3个公共子网,并在它们之间部署了3个nat网关。
请注意aws_nat_gateway子网net_id中添加的$ {count.index}会引发错误
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}"
}
}
答案 0 :(得分:3)
您应该改用${data.aws_subnet.public_subnets.*.id[count.index]}
。这将使用splat
operator返回迭代子网的列表,然后根据当前计数索引进行索引。