Hi,
I am slightly confused about the layout you have, can you confirm how many state files you end up with at the end of the process? You do have to define the input and outputs at each stage. What I typically end up with is something like this:
/modules
/modules/vpc
/modules/database/
/dev
/test
/prod
In /dev /test and /prod I have the same
main.tf,
variables.tf and
outputs.tf across the three environments. If I change the files in one place, I copy them to the other directories as well. I sometimes have
outputs.tf to allow me to get outputs from these environments into other modules, but in most cases I just have
main.tf and
variables.tf.
So for example here is one
main.tf file:
module "vpc" {
source = "../modules/vpc"
tags = "${var.tags}"
vpc_network = "${var.vpc_network}"
}
module "database" {
source = "../modules/database"
vpc_id = "${module.vpc.vpc_id}"
database_password = "${var.database_password}"
database_subnets = ["${module.vpc.database_subnets}"]
tags = "${var.tags}"
}
Here is the
variables.tf in my /dev directory:
variable "db_password" {
description = "DB Admin Password"
}
variable "tags" {
description = "Map of default tags to assign to the resources."
type = "map"
}
variable "vpc_network" {
description = "IP address allocation of the VPC for the environment"
}
Here is the
variables.tf in my VPC module:
variable "tags" {
description = "Map of default tags to assign to the resources."
type = "map"
}
variable "vpc_network" {
description = "IP address allocation of the VPC for the environment"
}
Here is
outputs.tf in the VPC module:
output "vpc_id" {
value = "${
aws_vpc.main.id}"
}
output "database_subnets" {
value = ["${aws_subnet.database.*.id}"]
}
I never nest modules more than one deep otherwise you end up in trouble later on with nested outputs etc. If I have instances where I don't want to have a specific module in an environment it just gets left out of
main.tf. Variable inputs in the environment modules are usually sources via tfvars files.
Does that help?
Andrew.
________________________________________
From:
terrafo...@googlegroups.com [
terrafo...@googlegroups.com] on behalf of Wayne Pascoe [
anonymou...@gmail.com]
Sent: 04 January 2018 09:59
To: Terraform
Subject: [terraform] Confused about passing variables to and from modules - duplication required ?
--
This mailing list is governed under the HashiCorp Community Guidelines -
https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
GitHub Issues:
https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Terraform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
terraform-too...@googlegroups.com<mailto:
terraform-too...@googlegroups.com>.
To view this discussion on the web visit
https://groups.google.com/d/msgid/terraform-tool/37e952a5-e5ba-4987-adcf-adab692132fd%40googlegroups.com<
https://groups.google.com/d/msgid/terraform-tool/37e952a5-e5ba-4987-adcf-adab692132fd%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit
https://groups.google.com/d/optout.