Using hooks in Terragrunt gives me almost all I can imagine, but I am looking for ways to be able to run them conditionally.
There are 2 use cases:
Any ideas or workarounds?
Run bash for Linux and PowerShell script for Windows (or even cygwin, which has different commands comparing to Linux)
This use case makes a ton of sense, since the script itself can't do such a check, but Terragrunt could. A PR for this would be very welcome.
Be able to enable or disable hook if Terraform variable or environment variable is set
Couldn't your script check for that env var and exit accordingly?
Yes, a script can do that but I think this code is more general:
after_hook "copy_main_variables_on_windows" {
commands = ["init"]
execute_if = "${var.os_name == "Windows"}"
execute = ["cp.bat", "main_variables.tf", "."]
}
after_hook "copy_main_variables_on_linux" {
commands = ["init"]
execute_if = "${var.os_name != "Windows"}"
execute = ["cp.sh", "main_variables.tf", "."]
}
Also having ${get_os_name()} can be handy for this reason.
This is now possible using conditionals and get_platform.
Most helpful comment
Yes, a script can do that but I think this code is more general:
Also having
${get_os_name()}can be handy for this reason.