Terraform v0.12.x
I thought I understood Terraform modules for code re-use after reading the docs, but apparently not.
Say I want to build a target group+EC2 instance infrastructure. I have this directory structure.
/terraform
/terraform/green.tf
/terraform/blue.tf
/terraform/module_ec2/ec2.tf
/terraform/module_tg/tg.tf
For example, /terraform/module_ec2/ec2.tf
has this
resource "aws_instance" "ec2" {
ami = var.ami
availability_zone = var.availability_zone
....
}
and /terraform/module_tg/tg.tf
has
resource "aws_lb_target_group" "tg" {
name = var.tg_name
...
}
I want blue.tf
and green.tf
to build their respective target group+EC2 infrastructure by using module_tg
and moodule_ec2
and just passing to them the respective key/value pairs each module needs. How can I do this, that is, what would be contents of blue.tf
and green.tf
?
module "ec2" { source="./module_ec2" ... } ...
– luk2302blue.tf
andgreen.tf
files? If so, how can I just then build theblue.tf
and notgreen.tf
, and visa-versa? – Chris Fblue
andgreen
targets separately, but still have code re-use for the other modules? Maybe you can put this in an answer, because it all makes sense. Note that I have files (non-modules) common to bothblue
andgreen
deployments. Thanks! – Chris Fgreen
run that I need in theblue
run? For example, if thegreen
run creates an EBS volume, how can theblue
run get it? – Chris F