-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
run_cmd()
outputs to terragrunt stdout
#3850
Comments
Use https://terragrunt.gruntwork.io/docs/reference/built-in-functions/#run_cmd |
How do I add that flag to terragrunt in pipelines? Also having the command output in debug logs is useful, and that flag redacts the command output from the debug logs. |
You put it in the HCL for You can write to stderr from |
Hold up, this is intended behavior!? What possible process or problem is solved by interleaving the output of a command (whose output is returned as a value) with terragrunt's other output? It doesn't even get the prefix + formatting treatment like the rest of terragrunt's output does. |
Fwiw I agree that having raw stdout instead of the wrapped "INFO terraform:" stdout treatment feels inconsistent. In normal circumstances I would expect subshelled processes to log to a parent process logger. |
It does also do this, though only in debug logs. |
I totally agree that it would have been better design to start with, but this is an old HCL function, and removing the need to use We try really hard to avoid breaking changes, especially in HCL configurations, as it's a lot harder to have people to change those than CLI arguments. What we've considered doing is simply introducing a new HCL function with better defaults and deprecating locals {
value = exec("echo", "hello")
debugged_value = exec("--tg-x-debug", "echo", "hello")
} Where the call to populate The time it makes the most sense to start talking about this kind of thing is next week, when we release experimental support for the new In the interim, I recommend that you just consider the default way to use run_cmd("--terragrunt-quiet", ...) That's what I do. |
Oh you give the --terragrunt-quiet to run_cmd? That's a bit - unintuitive, but definitely flexible! (Does HCL support key word arguments for functions? I do want to distinguish the concept of "debug logging" from "interleaving output" though. Currently, terragrunt will also include the output of the command in its debug logs, but with this quiet flag it will suppress the debug logs as well. I understand not interleaving output would be a breaking change (though I would argue that "breaking changes" to the stdout have been made before. Much more significant ones at that.) |
We really do try to to minimize them 😁 We generally only introduce breaking changes to Terragrunt terminal output if there's a significant change to the QoL of Terragrunt users that is infeasible otherwise. We're also trying to get better about giving users a way to gradually adopt breaking changes, rather than doing it all at once with Strict Mode. HCL functions end up calling Golang functions, so we can customize the logic for any Terragrunt-native HCL function however we like (within reason)! The only functions we don't have that level of control over are OpenTofu/Terraform-native HCL functions, as we pull those in via a pinned dependency on an old version of Terraform (for now, at least). Giving flags to the I recommend adding debug logs to the e.g. #!/usr/bin/env bash
>&2 echo "DEBUG: run_cmd - This won't write to stdout, and won't be pulled into the attribute run_cmd is assigned to!" |
I understand wanting to avoid breaking changes. One disconnect I want to clear up: it seems you keep referring to "output on run" as "debug logging", whereas when I have been saying "debug logging" I've been referring to the debug logger, such as here: https://github.com/gruntwork-io/terragrunt/blob/main/config%2Fconfig_helpers.go#L387 Using the proper logger allows folks to enable or disable debug logging at invocation without needing to change source code. However, the way the code is currently written, I cannot suppress this output which is breaking my pipelines without also suppressing the output in debug logs. |
For what it's worth I'm a huge fan of mechanisms like your strict mode to introduce breaking changes! Makes me think of things like |
I get where you're coming from, @ThisGuyCodes . To be clear, I think it would be better design for
I think that would be a smoother and more flexible design. We'll look to implement something like that in the future for a different HCL function like For the sake of Pipelines, you can suppress output while debugging, as I understand it. If you use a combination of |
I've checked a bunch of releases and it looks like the version v0.46.0 is affected, but v0.45.18 is not. |
Describe the bug
Using
run_cmd
causes the ran commands output to appear onterragrunt
s stdout.Steps To Reproduce
Steps to reproduce the behavior, code snippets and examples which can be used to reproduce the issue.
Be sure that the maintainers can actually reproduce the issue. Bug reports that are too vague or hard to reproduce are hard to troubleshoot and fix.
terragrunt plan
, orterragrunt show -json $PLANFILE
for that matter (which is my issue) will show the output ofls
mixed in the stdout fromterragrunt
.Demo repo is here: https://github.com/thisguycodes/terragrunt-run_cmd-bug
Expected behavior
The command given to
run_cmd()
has its output captured, and doesn't show onterragrunt
s stdout.Versions
Additional context
While this generally muddies the output; specifically when I try to use
terragrunt show -json $PLANFILE > tfplan.json
it makes the resulting file invalid json.The text was updated successfully, but these errors were encountered: