I am using terragrunt. I have following declared in 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"
}
}
I want to use it in terraform-aws-modules/rds/aws module, as following:
subnet_ids = data.aws_subnets.selected.ids
But I get an error:
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.
What am I doing wrong here? It used to work...
If I right understood you put this data.tf
next to the terragrunt.hcl
where you are passing information to the module rds_postgres_primary
.
Please try instead declare in terragrunt.hcl
:
locals {
subnet_ids = data.aws_subnets.selected.ids
}
inputs = {
subnet_ids = local.subnet_ids
}