Hey. I have a little bit "strange" question about execute stage, i want to use my own script like
terraform {
source = "git::[email protected]:users/mybash.git//app?ref=v0.0.1"
extra_arguments "custom_vars" {
commands = [
"apply",
]
arguments = [
"-var-file=config.tfvars",
]
env_vars = {
URL = "${run_cmd("myscript.sh", "params")}"
}
}
after_hook "cleanup" {
commands = [
"apply",
]
execute = ["myscript.sh", "params"]
run_on_error = true
}
}
where source is a github repo with my own script.
Is it possible or not to use it like this ?
As I can see terragrunt can download this repo, but i have no idea how i can use it in my code...
sorry for my bad English and if this question doesn't have any sense.
I don't think we support this right now since there is no way to get the path to the script.
With that said, here is a workaround. The working directory for the hooks is the directory where the terragrunt.hcl lives. So technically, you could have a script in your PATH that can take in the relative script path from the module directory as an arg, and execute that script after looking for it in the terragrunt cache.
But I think having a function like get_terragrunt_working_directory would be a nice addition, so you could do:
execute = ["${get_terragrunt_working_directory()}/myscript.sh"]
for my opinion it should be like
terraform {
extra_arguments "custom_vars" {
env_vars = {
URL = "${run_cmd("${get_terragrunt_working_directory(helpers.script1)}/myscript.sh", "params")}"
TTL = "${run_cmd("${get_terragrunt_working_directory(helpers.myscript2)}/getttl", "params")}"
}
}
}
helpers {
script1 = "git::[email protected]:users/mybash.git//app?ref=v0.0.1"
myscript2 = "git::[email protected]:fixme/goutil.git//app?ref=v0.0.3"
}
It would be a nice feature to empowering!