terragrunt icon indicating copy to clipboard operation
terragrunt copied to clipboard

Option to prefix *-all terraform output with working-dir label

Open lorengordon opened this issue 4 years ago • 10 comments

Right now, all terraform output is unmodified, which makes a lot of sense for regular terraform commands because they are only working on one config at a time and the output can be captured/used for other purposes.

But with the *-all commands, the terraform output of parallel configs just blends together and it is very difficult to determine what line of output is associated with which config.

For example, running validate-all, I don't know which config succeeded and which failed.

Success! The configuration is valid.

Error: Missing required argument

  on main.tf line 39, in output "repos":
  39: output "repos" {

The argument "value" is required, but no definition was found.

I'm suggesting that, only for the *-all commands, prefix terraform output the same way the terragrunt output is handled, so we get something like this...

[configs/dev/foo] Success! The configuration is valid.

[configs/dev/bar] Error: Missing required argument
[configs/dev/bar] 
[configs/dev/bar]   on main.tf line 39, in output "repos":
[configs/dev/bar]   39: output "repos" {
[configs/dev/bar] 
[configs/dev/bar] The argument "value" is required, but no definition was found.

This way we can filter the log very easily to see all the messages for a given config.

lorengordon avatar May 22 '20 15:05 lorengordon

Linking to a related issue, https://github.com/gruntwork-io/terragrunt/issues/74. I think both options would be useful.

lorengordon avatar May 22 '20 15:05 lorengordon

This seems like a good idea. However, it needs a little more thought, as for some commands (e.g., output), we don't want to mess with stdout or stderr. That said, a PR to add this functionality, with some flag to disable it (e.g., --terragrunt-no-log-prefix) is very welcome!

brikis98 avatar May 23 '20 13:05 brikis98

+1 i want to see this as a feature. even if its not enabled by default. something like --terragrunt-enable-log-prefix

ITJamie avatar Mar 26 '21 13:03 ITJamie

+1 for this. Even something at the top of the plan just saying Plan for directory: /foo/bar/baz would be enough for us.

nickmaccarthy avatar Apr 28 '21 14:04 nickmaccarthy

I've found I can only use run-all commands with --terragrunt-parallelism 1. It's incredibly slow, but it's the only way the output still makes sense.

lorengordon avatar Jan 15 '22 16:01 lorengordon

We are also plagued by this problem.

I had these ideas:

  1. Prepend all lines with the module name/path
  2. Buffer and group the output per module and print later with a header or something
  3. Colourise the output to identify each module

prefix terraform output the same way the terragrunt output is handled

Where does this "working-dir label" come from exactly?

max-rocket-internet avatar Jan 18 '22 15:01 max-rocket-internet

I really want this fixed but while it's not there's a possible workaround...

terraform {
  extra_arguments "plan_file" {
    commands = ["plan"]
    arguments = ["-out=${get_terragrunt_dir()}/tfplan.binary"]
  }
}

You then do terragrunt run-all plan.

Then for each tfplan.binary you have now you can do a terragrunt show tfplan.binary

meyerbro avatar Feb 16 '22 14:02 meyerbro

Hi there,

just would like to share our workaround for this case: ` using before_hook on root level to get more info about running module / config-dir right at the beginning

terraform {
  before_hook "before_hook" {
    commands     = ["apply", "plan", "import", "push"]
    execute      = ["echo", "Running Terraform"]
    run_on_error = true
  }
}
....

Result:

Group 1
- Module /home/myname/terraform/env/test/local-cluster/config

time=2022-04-27T00:47:33+02:00 level=info msg=Executing hook: before_hook prefix=[/home/myname/terraform/env/test/local-cluster/config]
Running Terraform
...

rmammadli avatar Apr 26 '22 23:04 rmammadli

@rmammadli I feel like that's only a partial solution, and unfortunately does not address the primary use case in the OP. Configs run in parallel and their output is interleaved. Simply outputting the path before/after any given config runs is most useful when run one at a time. This feature request is primarily about running multiple configs at once in parallel, where it is unknown which line of output is associated to any particular config.

lorengordon avatar Apr 27 '22 00:04 lorengordon

Sometime the text output of run-all commands is actually totally scrambled, like this for example:

      + id                                    = (known after apply)
  # module.cache.aws_cloudwatch_metric_alarm.high_database_memory_usage[0] will be created
      + insufficient_data_actions             = [
  + resource "aws_cloudwatch_metric_alarm" "high_database_memory_usage" {
          + "arn:aws:sns:eu-west-1:6666666666:xxxxxx-yy-xxxxxx-xxxx-xxxx",
        ]

max-rocket-internet avatar May 31 '22 09:05 max-rocket-internet

Fixed in https://github.com/gruntwork-io/terragrunt/releases/tag/v0.45.1

denis256 avatar Apr 03 '23 21:04 denis256