Posibble to access CLI parameter values in the terragrunt.hcl?

Hi there,
I’m using terragrunt for little while but first time poster here, so bear with me if this was asked before or didn;t ask the question right.

In our project, we use --terragrunt-source in our project to provide the path to out terraform modules. We also use terraform fmt (in a script) as a before_hook. As various users setup their tf-modules directory differently, as per their liking, I found it’s next to impossible to writing the script (executes, something like: terraform fmt ${tf_module} in it), which works for the team. I was wondering, if there any way the commnd-line parameter values can be imported as ENV_VARIABLE or something so that it’s accessible in the terragrunt.hcl, so that I can use that as a parameter to supply to the script? Or any other way to achieve the similar thing?

Any help or pointing me t the right direction would be greatly appreciated!!

-S

Any one with any thought(s) at all?
All I need is to be able to capture the Terraform module-path in a variable (or something like that) so that I can feed that info to the script that runs as before_hook - any pointer(s)?

-S

Hi @dsantanu ,

Hooks run from the directory with the terraform module, except for hooks related to terragrunt-read-config and init-from-module . These hooks run in the terragrunt configuration directory (the directory where terragrunt.hcl lives). Given that, setting the hook to terraform fmt (no arg) should have the desired effect.

Hope this helps!
- Yori

Hi @yoriy ,Thanks for the reply.
I tried that but unfortunately that doesn’t actually work. The Terragrunt documentation on before_hook is confusing, IMO - the hook doesn’t run from the actual terraform module directory but in/from the cached terragrunt directory, like: .terragrunt-cache/ZcYtXnHH8M36Mz-ntqxwr-UxFQY/dCWM_rlVNlHFMGswUwt4pOE2BH4, hence terraform fmt fixes stuff in that temp location but not the actual code base, which makes the whole purpose useless.
Or, am I missing something here?

-S

So, does it mean there is no way to get the actual/physical location of the tf-modules in HCL if the module-path is supplied using --terragrunt-source?

Hi sorry for the delay in responding here.

So, does it mean there is no way to get the actual/physical location of the tf-modules in HCL if the module-path is supplied using --terragrunt-source ?

Yes that is correct. That said, I think we might be able to implement a helper function that flows this through to the config when set. I filed Add helper function to get `--terragrunt-source` · Issue #1555 · gruntwork-io/terragrunt · GitHub so you can track the feature request.

thanks @yoriy !!
It will really useful to run e.g. terraform fmt on the actual location as the post-hook - I’m stuck at there.