我正在使用 terragrunt。 我在 data.tf 中声明了以下内容:
data "aws_vpcs" "this" {
tags = {
terraform = "true"
project_name = var.project_name
}
}
data "aws_vpc" "this" {
id = element(tolist(data.aws_vpcs.this.ids), 0)
}
data "aws_subnets" "selected" {
filter {
name = "vpc-id"
values = [data.aws_vpc.this.id]
}
tags = {
environment = var.environment
project_name = var.project_name
region = var.region
service = "database"
}
}
我想在 terraform-aws-modules/rds/aws 模块中使用它,如下:
subnet_ids = data.aws_subnets.selected.ids
但是我收到错误:
Error: Reference to undeclared resource
│
│ on rds.tf line 40, in module "rds_postgres_primary":
│ 40: subnet_ids = data.aws_subnets.selected.ids
│
│ A data resource "aws_subnets" "selected" has not been declared in the root
│ module.
我在这里做错了什么?以前有用过...
如果我没理解错的话,您可以将其
data.tf
放在将信息传递给模块的 terragrunt.hcl
旁边 rds_postgres_primary
。
请尝试在
terragrunt.hcl
: 中声明
locals {
subnet_ids = data.aws_subnets.selected.ids
}
inputs = {
subnet_ids = local.subnet_ids
}