Skip to content
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

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

Closed
lorengordon opened this issue May 22, 2020 · 11 comments · Fixed by #2493
Closed

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

lorengordon opened this issue May 22, 2020 · 11 comments · Fixed by #2493
Labels
enhancement New feature or request trial project Suitable for trial projects

Comments

@lorengordon
Copy link
Contributor

lorengordon commented May 22, 2020

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
Copy link
Contributor Author

Linking to a related issue, #74. I think both options would be useful.

@brikis98 brikis98 added enhancement New feature or request help wanted and removed enhancement New feature or request help wanted labels May 23, 2020
@brikis98
Copy link
Member

brikis98 commented May 23, 2020

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!

@ITJamie
Copy link

ITJamie commented Mar 26, 2021

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

@nickmaccarthy
Copy link

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

@infraredgirl infraredgirl added the trial project Suitable for trial projects label Nov 1, 2021
@lorengordon
Copy link
Contributor Author

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.

@max-rocket-internet
Copy link

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?

@meyerbro
Copy link

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

@rmammadli
Copy link

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
...

@lorengordon
Copy link
Contributor Author

@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.

@max-rocket-internet
Copy link

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",
        ]

@denis256
Copy link
Member

denis256 commented Apr 3, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request trial project Suitable for trial projects
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants