Terragrunt: Override map variable declared inside parent .tfvars

Created on 12 Apr 2018  路  2Comments  路  Source: gruntwork-io/terragrunt

Hello everyone.

I need to have a map variable (that contains tags) and is used in all my modules. 搂
I have this file structure:

# /env.tfvars
base_tags = {
   "Tag1" = "Value1"
   "Tag2" = "Value2"
}

# /terraform.tfvars
terragrunt = {
  # Configure root level variables that all resources can inherit
  terraform {
    extra_arguments "bucket" {
      commands = ["${get_terraform_commands_that_need_vars()}"]

      required_var_files = [
        "${get_tfvars_dir()}/${find_in_parent_folders("env.tfvars", "ignore")}",
      ]
    }
  }
}

# /mymodule/terraform.tfvars
terragrunt = {
  # Include all settings from the root terraform.tfvars file
  include = {
    path = "${find_in_parent_folders()}"
  }
}

In one of my modules I need to override some values of the base_tags map, so I thought that I would be fine with something like:

# /mymodule2/terraform.tfvars
terragrunt = {
  # Include all settings from the root terraform.tfvars file
  include = {
    path = "${find_in_parent_folders()}"
  }
}

base_tags = {
   "Tag1" = "Value3"
   "Tag2" = "Value2"
}

I redeclared Tag2 because I thought that the variable would be completely overwritten, but when I terragrunt apply, I still see the original tags and not the customized one.

Is there a way to accomplish this?

question

All 2 comments

I'm guessing the cause for this is that when you use required_var_files, it adds those files using -var-file arguments, and -var-file arguments override any variables pick up "by default", such as terraform.tfvars. You might be able to work around this by adding terraform.tfvars to the end of the required_var_files list, so it overrides env.tfvars instead.

Didn't think of that... Worked like a charm!

Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zachwhaley picture zachwhaley  路  3Comments

lsc picture lsc  路  4Comments

MacFlurry picture MacFlurry  路  4Comments

shaharmor picture shaharmor  路  3Comments

dzirg44 picture dzirg44  路  3Comments