---
module "security_rules_staging" {
source = "modules/security_rules/staging"
}
module "security_rules_production" {
source = "modules/security_rules/production"
}
module "security_rules_infrastructure" {
source = "modules/security_rules/infrastructure"
}
------
And every of those directory will contain the usual provider with the variable file . For example on security_rules/infrastructure I got in the provider file:
----
provider "aws" {
access_key = "${var.access_key}"
secret_key = "${var.secret_key}"
region = "${var.region}"
}
module "vpc_infrastructure" {
source = "../../../modules/vpc/infrastructure/"
region = "${var.region}"
}
output "aws_vpc_infrastructure_id" {
value = "${module.vpc_infrastructure.aws_vpc_infrastructure_id}"
}
----
So that will call the VPC module creating all the relevant parts for the VPC: subnets/routing tables/gateways....
Now... with the plan parameter i am trying to pass variables to ALL those parts (example var.region) but the value of the variable seems to get lost at some stage and I am not sure if I am setting all this right or what the issue might be...
I would really like to get some values from some of the modules into others so to make this pretty flexible so avoid hard-coding as much as I can...
Any help on these regards?
Many thanks!!
Another even terser approach is to rely on the fact that providers can be configured via environment variables. If you use the appropriate env vars (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_DEFAULT_REGION). You can omit `provider {}` blocks from your config entirely. This is the strategy I personally like best.