Reputation: 77
Prelim info before my question....
File structure:
-thing.tf
--module1
---outputs.tf
--module2
---vars.tf
---main.tf
thing.tf
module "module2" {
source = "./module2"
vpc_id = "${module.vpc_utility.vpc_id}"
private_subnets = ["${module.vpc_utility.private_subnets}"]
}
MODULE1 INFO: VPC_UTILITY is created successfully beforehand and outputs are:
output "vpc_id" {
description = "The ID of the VPC"
value = "${module.vpc_utility.vpc_id}"
}
output "private_subnets" {
description = "List of IDs of private subnets"
value = ["${module.vpc_utility.private_subnets}"]
}
MODULE2 INFO: vars.tf
variable "vpc_id" {
type = "string"
}
variable "private_subnets" {
type = "list"
}
main.tf
resource "aws_elasticache_subnet_group" "subnet_group" {
name = "subnet_group"
**subnet_ids = ["${module.vpc_id.private_subnets}"]**
}
ERRORS:
-unknown module referenced: vpc_id
-reference to undefined module "vpc_id"
Neither the vpc_id from the module or the subnets are being recognized from Module1 into Module2.
What is the syntax for putting the correct value in for multiple subnets in aws_elasticache_subnet_group.subnet_group.subnet_ids
?
I cant seem to find a straight answer or the format changes based on versions of Terraform. Im on version 11 if that matters.
Upvotes: 0
Views: 5456
Reputation: 77
Figured it out...its sort of vaguely in the Terraform docs in the 'Input Variable Configuration' page at https://www.terraform.io/docs/configuration/variables.html
Using the above sample code, I changed the subnet_ids = ["${module.vpc_id.private_subnets}"] line in the main.tf file to: ["${var.private_subnets}"] I had tried this before but lacked the enclosing [] For future readers heres my thinking... So main.tf pulls the list of subnets from ["${var.private_subnets}"] which points to the vars.tf file and looks at:
variable "private_subnets" {
type = "list"
}
This value is gathered from the thing.tf file which declares the value of private_subnets based on what its input is which in my case is the Output of Module1.
output "private_subnets" {
description = "List of IDs of private subnets"
value = ["${module.vpc_utility.private_subnets}"]
}
Hope this helps out someone later on because this isnt clear from any docs ive been able to find that were current up to today.
Also if someone sees this and sees that my thinking is wrong on this then please correct me.
Upvotes: 0