Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unused bucket and region variables in account.tfvars #6

Open
hammadzz opened this issue Jan 20, 2018 · 7 comments
Open

Unused bucket and region variables in account.tfvars #6

hammadzz opened this issue Jan 20, 2018 · 7 comments

Comments

@hammadzz
Copy link

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

@brikis98
Copy link
Member

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

@hammadzz
Copy link
Author

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
Copy link
Author

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
Copy link
Author

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::git@github.com: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
Copy link
Author

hammadzz commented Jan 23, 2018

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?

@kelsmj
Copy link

kelsmj commented Mar 20, 2019

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

@dserkin
Copy link

dserkin commented Mar 20, 2019

@hammadzz @kelsmj there is no support for it, but there is a workaround I use:

terragrunt = {
  terraform {
    source = "git::git@github.com: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()}"
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants