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!!
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)?
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.
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?
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?
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 ?
you could pass the directory you want to run terraform fmt in as an env variable, then get the value using get_env as an input to a script you run with an after_hook, like: