gruntwork-io / terragrunt

Terragrunt is a flexible orchestration tool that allows Infrastructure as Code written in OpenTofu/Terraform to scale.
https://terragrunt.gruntwork.io/
MIT License
8.04k stars 974 forks source link

`get_parent_terragrunt_dir()` function behavior does not match documentation #3175

Closed stefan-matic closed 3 months ago

stefan-matic commented 4 months ago

Describe the bug

The Terragrunt documentation for get_parent_terragrunt_dir() shows an example of how the function can be used for fetching values in common.tfvars.

I've replicated the example setup on my end with the terraform-aws-modules/vpc/aws module and get_parent_terragrunt_dir() still outputs the location of /app1/common.tfvars instead of /common.tfvars.

When used with the include block, the get_parent_terragrunt_dir() function works correctly.

Steps To Reproduce

Follow the example setup in the documentation

terraform {
  source = "tfr:///terraform-aws-modules/vpc/aws//?version=5.8.1"

  extra_arguments "common_vars" {
    commands = [
      "apply",
      "plan",
      "import",
      "push",
      "refresh"
    ]

    arguments = [
      "-var-file=${get_parent_terragrunt_dir()}/common.tfvars"
    ]
  }
}

Expected behavior

The get_parent_terragrunt_dir() function should output the parent terragrunt.hcl location, not the child (when not used together with the include block).

If the get_parent_terragrunt_dir() function cannot work as expected without the include block, the documentation needs to be updated as it's misleading.

Nice to haves

❯ terragrunt plan
╷
│ Error: Failed to read variables file
│ 
│ Given variables file /workspace/app1/common.tfvars does not exist.
╵
ERRO[0001] terraform invocation failed in /workspace/app1/.terragrunt-cache/5eyWb_lSjiAZ9XRfNWyS_pGxNOE/ThyYwttwki6d6AS3aD5OwoyqIWA  prefix=[/workspace/app1] 
ERRO[0001] 1 error occurred:
        * [/workspace/app1/.terragrunt-cache/5eyWb_lSjiAZ9XRfNWyS_pGxNOE/ThyYwttwki6d6AS3aD5OwoyqIWA] exit status 1

Versions

levkohimins commented 4 months ago

Hey @stefan-matic I wasn't able to reproduce the issue, the example I used https://github.com/levkohimins/terragrunt-issue-3175 Most likely you misunderstood the example.

levkohimins commented 3 months ago

No news is good news. If you find problems feel free to open a new issue or reopen this one.