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

Reusing locals in the tree #3066

Open
pritho opened this issue Apr 16, 2024 · 2 comments
Open

Reusing locals in the tree #3066

pritho opened this issue Apr 16, 2024 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@pritho
Copy link

pritho commented Apr 16, 2024

Describe the solution you'd like
Having a older structure like this:

├── dev
│   ├── stage.hcl
│   └── app1
│       └── bucket
│           └── terragrunt.hcl
├── qual
│   ├── stage.hcl
│   └── app1
│       └── bucket
│           └── terragrunt.hcl
├── global.hcl
└── terragrunt.hcl

I end up having this redundant code in every single terragrunt.hcl file:

locals {
  stage_vars          = read_terragrunt_config(find_in_parent_folders("stage.hcl"))
  resource_group_name = local.stage_vars.locals.resource_group_name
  stage_name = local.stage_vars.locals.stage_name
}

I would like to define said code once in the root terragrunt.hcl file

Describe alternatives you've considered
The docs regarding globally-defined-locals also is more or less the same and doesn't help.

Additional context
Is there already WIP where I could maybe participate?
Or did I miss a specific feature solving my use-case?

@pritho pritho added the enhancement New feature or request label Apr 16, 2024
@denis256
Copy link
Member

Hi,
can be used include with merge_strategy = "deep"

# dev/app1/terragrunt.hcl
include "root" {
  path = find_in_parent_folders()
  merge_strategy = "deep"
}

# parent terragrunt.hcl

locals {
  stage_vars          = read_terragrunt_config(find_in_parent_folders("stage.hcl"))
  resource_group_name = local.stage_vars.locals.resource_group_name
  stage_name = local.stage_vars.locals.stage_name
}

Simplified example in: https://github.com/denis256/terragrunt-tests/tree/master/reuse-locals

@pritho
Copy link
Author

pritho commented Apr 18, 2024

perfect, thanks so much.
I created a documentation PR for this: #3070

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

No branches or pull requests

2 participants