Я пытаюсь динамически объявить несколько источников данных aws_nat_gateway
, получая список общедоступных подсетей через источник данных aws_subnet_ids
.Однако, когда я пытаюсь установить параметр count
равным длине идентификаторов подсети, я получаю сообщение об ошибке: 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.