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

[Feature Request] Provide way to check whether terragrunt is called by terragrunt #2674

Open
juljaeg opened this issue Aug 18, 2023 · 5 comments · May be fixed by #2759
Open

[Feature Request] Provide way to check whether terragrunt is called by terragrunt #2674

juljaeg opened this issue Aug 18, 2023 · 5 comments · May be fixed by #2759
Labels
enhancement New feature or request needs design We need to flesh out the design before we can resolve the issue

Comments

@juljaeg
Copy link

juljaeg commented Aug 18, 2023

Describe the solution you'd like

I'd like to have a function or variable enabling me to distinguish whether the current terragrunt execution was initiated by another terragrunt run. This is e.g. the scenario when you reference another directory containing a terragrunt.hcl in a dependency block. A way to handle those scenarios would be beneficial when e.g. another state would need be addressed when fetching outputs using the dependency block.

Describe alternatives you've considered

We distinguish states partly by using environment variables where we would have 60+ directories (each environment) for 30+ teams. This does work quite well except when a dependency block is used and a state file should be referenced which is not addressable using the environment variables.

We evaluated mirroring the state address components in the directory structure, but yielded this will become unmaintainable with growing number of teams and environments. Where also environments come and go which would mean deleting directories across 30+ teams.

Additional context

I see two possible ways to address this:

  1. Have a function e.g. is_silent_run_by_terragrunt which enables me to detect this scenario. Optionally this may be extended to also contain the operation e.g. output to further distinguish. Of course scenarios like run-all make this a bit hard to define when this function will return what value as run-all also runs terragrunt in a subdirectory.
  2. Being able to attach environment variables in the dependency block which can be read in the other terragrunt configuration using get_env. This solution seems a bit more flexible to me.

What do you think?

@juljaeg juljaeg added the enhancement New feature or request label Aug 18, 2023
@denis256 denis256 added the needs design We need to flesh out the design before we can resolve the issue label Aug 18, 2023
@denis256
Copy link
Member

Hello,
Normally, Terragrunt does not invoke Terragrunt again (unless it's invoked through the run_cmd feature).
Most probably, the intention is to determine if the HCL file is included from another location.

@juljaeg
Copy link
Author

juljaeg commented Aug 21, 2023

Hi, thanks for the response. 😄 Not sure whether it is really calling terragrunt internally. When the path used in a dependeny block in a configuration (root hcl) contains also a terragrunt.hcl (sibling hcl): how is it handled to get the outputs? Does it read the sibling hcl natively and process it?

I am assuming parent and sibling hcl's generate a different state backend configuration. If it does that, I agree. What I mean is: there is no technical include represented using a include block. Just a dependency block.

EDIT: Just skipped through the code and found this:

func runTerragruntOutputJson(targetTGOptions *options.TerragruntOptions, targetConfig string) ([]byte, error) {

@juljaeg
Copy link
Author

juljaeg commented Aug 22, 2023

Most probably, the intention is to determine if the HCL file is included from another location.

The more I think of it, I think by included you mean the dependency block path attribute. If this would be covered as well it would be quite nice because that would also cover scenarios where optimization takes place (saw some in the code).

@juljaeg
Copy link
Author

juljaeg commented Sep 5, 2023

@denis256 Can we support in the further process somehow? Do we need to supply a RFC (design?)? We can also help by implementing.

@juljaeg
Copy link
Author

juljaeg commented Oct 17, 2023

I drafted something at #2759 but could not get some parts to work. Sorry for the rough code :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request needs design We need to flesh out the design before we can resolve the issue
Projects
Status: To do
Development

Successfully merging a pull request may close this issue.

2 participants