Unused bucket and region variables in account.tfvars
account.tfvars
# Root level variables that all modules can inherit. This is especially helpful with multi-account configs
# where terraform_remote_state data sources are placed directly into the modules.
tfstate_global_bucket = "terragrunt-state-global-non-prod"
tfstate_global_bucket_region = "us-east-1"
aws_profile = "non-prod"
Were tfstate_global_bucket and tfstate_global_bucket_region to be used in terraform.tfvars
The file is pulled in by every module: https://github.com/gruntwork-io/terragrunt-infrastructure-live-example/blob/master/non-prod/terraform.tfvars#L20. It's an example of how to set common variables that are used by all modules. That said, I'm not sure any of the example code in the infra-modules example repo is using those particular variables, so we should probably update the examples accordingly :)
Thanks. I was just confused by why it was there. It didn't make sense that these two variables would even be globally needed.
This example should include environment level variables. For example if you want to tag everything in QA with the environment name and everything in STAGE with the environment name.
I was thinking of making an envname.tfvar in each environment folder and figuring out the imports such that it imports all the account.tfvars like in this examples and lets you override/add to them. Then this envname.tfvar is imported in each resource file.
Here is how I have done it, as include on a file with an include doesn't work. directory structure
└── non-prod
├── account.tfvars
├── terraform.tfvars
└── us-east-1
└── stage
├── env.tfvars
└── postgresql
└── terraform.tfvars
config in non-prod/us-east-1/stage/postgresql/terraform.tfvars
terragrunt = {
# Terragrunt will copy the Terraform configurations specified by the source parameter, along with any files in the
# working directory, into a temporary folder, and execute your Terraform commands in that folder.
terraform {
source = "git::[email protected]:gruntwork-io/terragrunt-infrastructure-modules-example.git//postgresql?ref=v0.0.1"
required_var_files = [
"${get_parent_tfvars_dir()}/env.tfvars"
]
}
# Include all settings from the root terraform.tfvars file
include = {
path = "${find_in_parent_folders()}"
}
}
non-prod/us-east-1/stage/env.tfvars
environment = "stage"
A correction, the above doesn't work. This is quite miserable to learn and get right. I wish it was more like ansible. How do I debug required_var_files or path?
I agree. I would really like to see an example where I use something defined in account.tfvars in some of the child terraform.tfvars. I can't find an example anywhere....
@hammadzz @kelsmj there is no support for it, but there is a workaround I use:
terragrunt = {
terraform {
source = "git::[email protected]:gruntwork-io/terragrunt-infrastructure-modules-example.git//postgresql?ref=v0.0.1"
extra_arguments "common_vars" {
commands = ["${get_terraform_commands_that_need_vars()}"]
required_var_files = [
"${get_tfvars_dir()}/${find_in_parent_folders("env.tfvars", "")}"
]
}
}
include = {
path = "${find_in_parent_folders()}"
}
}