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.01k stars 971 forks source link

all_terraform_commands build-in function? #1044

Open sleungcy opened 4 years ago

sleungcy commented 4 years ago

How do I get a list of all terraform commands if I want to prepend an environment variable to all terraform commands? Should we add a built-in function to return list of all the terraform commands?

yorinasub17 commented 4 years ago

Adding a way to specify all terraform commands makes sense to me, although I would want a special case and logic instead of hardcoding all terraform commands to make it so that we don't have to maintain that list overtime as terraform adds new commands. Perhaps using something like ["*"] to mean all terraform commands?

sleungcy commented 4 years ago

I am not sure "*" should be used, because commands current also include other non-terraform related special cases. such as init, init_from_modules. I believe special cases such as 'init', 'init_from_modules', and 'terragrunt-read-config' shouldn't be defined under commands in the first place, as commands are really just referring to terraform commands.

all-terraform-commands() is more clear what it returns. If maintaining a separate list is a concern, what if this method just return a concatenation of all the other terraform commands list?

yorinasub17 commented 4 years ago

The problem is that the other lists are more straightforward to maintain because it is unlikely terraform will introduce a major new command, and people wouldn't expect it to contain new commands terraform introduces like 0.12upgrade. However, with something like all_terraform_commands, people will expect it to be ALL terraform commands, meaning that it needs to have everything, which is much harder to grasp.

include other non-terraform related special cases. such as init, init_from_modules

The only non-terraform special case in there is terragrunt-read-config, and for that it is only used in the hooks. init and init-from-module both involve terraform calls and I would expect it to be captured in all_terraform_commands.

I was also thinking that the ["*"] construct is only supported in extra_arguments to set environment variables for the command calls, at which point terragrunt-read-config is excluded.

maciejp-ro commented 2 years ago

commands = [get_terraform_command()] seems to do the trick for me - is there any edge case it would miss?