terragrunt-infrastructure-live-example icon indicating copy to clipboard operation
terragrunt-infrastructure-live-example copied to clipboard

Unused bucket and region variables in account.tfvars

Open hammadzz opened this issue 8 years ago • 7 comments

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

hammadzz avatar Jan 20 '18 17:01 hammadzz

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 :)

brikis98 avatar Jan 20 '18 23:01 brikis98

Thanks. I was just confused by why it was there. It didn't make sense that these two variables would even be globally needed.

hammadzz avatar Jan 22 '18 02:01 hammadzz

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.

hammadzz avatar Jan 22 '18 14:01 hammadzz

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"

hammadzz avatar Jan 22 '18 14:01 hammadzz

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?

hammadzz avatar Jan 23 '18 12:01 hammadzz

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....

kelsmj avatar Mar 20 '19 18:03 kelsmj

@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()}"
  }
}

dserkin avatar Mar 20 '19 19:03 dserkin