Hi,
I’ve a very simple module that creates a RDS instance that’s failing to create DB subnet Group.
I’m passing vpc_id
as a variable to the module for looking up subnets.
main.tf
used for apply
module "rds_instance" {
source = "../terraform-modules/terraform-aws-rds-cluster"
vpc_id = var.vpc_id
region = var.region
db_name = "test-instance"
}
main.tf
for module
data "aws_subnets" "private" {
filter {
name = "vpc-id"
values = [var.vpc_id]
}
}
resource "aws_db_subnet_group" "default" {
name = var.rds_subnet_group
description = "Our main group of subnets"
subnet_ids = data.aws_subnets.private.ids
}
resource "aws_db_instance" "default" {
...
...
}
This is failing with following error
│ Error: creating RDS DB Subnet Group (terraform-20230615220805359600000001): InvalidSubnet: Subnet IDs are required.
│ status code: 400, request id: 9aca2d3c-acab-4cb4-8293-a8714ed6ddbd
│
│ with module.rds_instance.aws_db_subnet_group.default,
│ on .terraform/modules/rds_instance/main.tf line 9, in resource “aws_db_subnet_group” “default”:
│ 9: resource “aws_db_subnet_group” “default” {
If I move the data lookup from module main.tf
to the actual main.tf
, it’s working.
Is there something wrong with the way variables are being passed into the module or just data lookups are supposed to happen outside the module?
Thanks for your inputs.