我试图通过aws_nat_gateway
数据源检索公共子网列表来动态声明多个数据aws_subnet_ids
源。但是,当我尝试将count
参数设置为等于子网 ID 的长度时,我收到一条错误消息The "count" value depends on resource attributes that cannot be determined until apply...
。
这几乎与他们文档中的示例直接矛盾!我该如何解决?他们的文件有问题吗?
我正在使用 Terraform v0.12。
data "aws_vpc" "environment_vpc" {
id = var.vpc_id
}
data "aws_subnet_ids" "public_subnet_ids" {
vpc_id = data.aws_vpc.environment_vpc.id
tags = {
Tier = "public"
}
depends_on = [data.aws_vpc.environment_vpc]
}
data "aws_nat_gateway" "nat_gateway" {
count = length(data.aws_subnet_ids.public_subnet_ids.ids) # <= Error
subnet_id = data.aws_subnet_ids.public_subnet_ids.ids.*[count.index]
depends_on = [data.aws_subnet_ids.public_subnet_ids]
}
我希望能够成功应用此模板,但出现以下错误:
Error: Invalid count argument
on ../src/variables.tf line 78, in data "aws_nat_gateway" "nat_gateway":
78: count = "${length(data.aws_subnet_ids.public_subnet_ids.ids)}"
The "count" value depends on resource attributes that cannot be determined
until apply, so Terraform cannot predict how many instances will be created.
To work around this, use the -target argument to first apply only the
resources that the count depends on.