Invalid value for input variable : Module inter-depedency

Hi,

I’m trying to use output value of one child module as input variable of another child module using some of the examples provided by Hashicorp. But I keep getting following error:

Code snippets:

root main.tf

module “shared_vpc_subnets” {
source = “./modules/subnets”

module “shared_vpc_ram_shares” {
source = “./modules/ram”
resource_arn_id = module.shared_vpc_subnets.subnet_arn_id

root variables.tf

variable “subnet_arn_id” {
type = string
description = “”
}

/modules/subnets/main.tf

resource “aws_subnet” “vpc_subnet” {
}

/modules/subnets/outputs.tf

output “subnet_arn_id” {
value = “${aws_subnet.vpc_subnet.arn}”
}

I alternatively tried using value = aws_subnet.vpc_subnet.arn to no luck.

/modules/ram/main.tf

resource “aws_ram_resource_association” “ram_shares” {
resource_arn = var.resource_arn_id
resource_share_arn = aws_ram_resource_share.ram_shares.arn
}

/modules/ram/variables.tf

variable “resource_arn_id” {
type = string
description = “”
}

Looks like there is some conversion of variable happening/required but I can’t figure why. Please let me know if I should provide further data.

Hi @jaeypatel,

The correct syntax for the output is

output "subnet_arn_id" {
  value = aws_subnet.vpc_subnet.arn
}

Though of course the string conversion shouldn’t be a problem here, since the expected type is a string anyway.

I don’t see what the problem could be from the limited example, perhaps making a standalone example would highlight the problem. One tool you can use here is to comment out the problematic assignment, and use the terraform console type function to inspect the module output to see exactly what you are dealing with.

1 Like