terragrunt: can't get get_parent_tfvars_dir() to work

Consider the following project:

/terragrunt live folder
├── terraform.tfvars <-- root
├── prd
│   ├── app1
│   |   └── terraform.tfvars <-- child

I’d like to access the terraform modules dir located one step above the folder where I have the root terraform.tfvars using get_parent_tfvars_dir() in the child terraform.tfvars as in: source = "${get_parent_tfvars_dir()}/../modules//app"

but get_parent_tfvars_dir() keeps returning the absolute location of the child terraform.tfvars /path/to/live/prd/app1 instead of returning /path/to/.

Is there anything i’m doing wrong ?

About this issue

  • Original URL
  • State: open
  • Created 7 years ago
  • Reactions: 3
  • Comments: 16 (11 by maintainers)

Most upvoted comments

I suppose this could be avoided by separating out the ideas of “where to get modules” and “what module to use”. i.e. the // syntax in Terraform.

A neat idea, assuming that all the children of a parent come use the same modules_source.

Note that we will be working on a relatively large refactor of Terragrunt to support the next version of Terraform and HCL2. You can find the rough proposal here: https://github.com/gruntwork-io/terragrunt/issues/466#issuecomment-386258812. That includes a new get_input helper you can use to read variables from other Terragrunt configs, which offers another way to handle source URLs where you store the common source in a variable somewhere and reference it everywhere else:

source = "${get_input("../common.tfvars", "modules_source"}//foo/bar"

I’ve run into same problem attempting to use get_parent_tfvars_dir() from a “child” config and getting the abs path of the child rather than the parent.

    extra_arguments "tls" {
      commands = ["${get_terraform_commands_that_need_vars()}"]

      env_vars = {
        TF_VAR_tls_crt_path = "${get_parent_tfvars_dir()}/..."
        TF_VAR_tls_key_path = "${get_parent_tfvars_dir()}/..."
      }
    }