i am relatively new to terraform and looking for some help here! i want to refer a module and have it deployed across multiple AWS regions. I also want to pass few environment variables into the module something like this:
module "aws-eu-central-1" {
source="git::https://<git-repo-url>"
export TF_VAR_REGION="eu-central-1"
export TF_VAR_TABLE_NAME="euc-accounts"
export TF_VAR_ES_ENDPOINT="euc-elasticsearch"
export TF_VAR_LOG_LEVEL="INFO"
}
module "aws-eu-west-1" {
source="git::https://<git-repo-url>"
export TF_VAR_REGION="eu-west-1"
export TF_VAR_TABLE_NAME="euw-accounts"
export TF_VAR_ES_ENDPOINT="euw-elasticsearch"
export TF_VAR_LOG_LEVEL="INFO"
}
module "aws-eu-west-2" {
source="git::https://<git-repo-url>"
export TF_VAR_REGION="eu-west-2"
export TF_VAR_TABLE_NAME="euw-accounts"
export TF_VAR_ES_ENDPOINT="euw-elasticsearch"
export TF_VAR_LOG_LEVEL="INFO"
}
i want my source code to get deployed across these regions and want to pass the environment variables to the module. how this can be done? thanks for the help!
You pass the variable to the terraform executable:
TF_VAR_REGION=eu-central-1 terraform plan
That creates the REGION variable which you can then pass to the module:
module "aws-eu-central-1" {
source="git::https://<git-repo-url>"
region="{var.REGION}"
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With