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

Fix error output in plan-all.. #789

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cli/download_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ func downloadTerraformSourceIfNecessary(terraformSource *TerraformSource, terrag
// before and after hooks (if any).
terragruntOptionsForDownload := terragruntOptions.Clone(terragruntOptions.TerragruntConfigPath)
terragruntOptionsForDownload.TerraformCommand = CMD_INIT_FROM_MODULE
terragruntOptionsForDownload.Logger = terragruntOptions.Logger
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does Clone not do this automatically?

Copy link
Author

@mariux mariux Jul 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the clone function sets up a new logger logging to the current ErrWriter.. which is not where the current logger is logging to..

I know this might not be the cleanest solution to just set it this way, but since it fixed it for me, i went for it.

maybe an actual go developer can come up with a cleaner implementation ;)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw it seems that ErrWriter and Logger are not really connected in a logical consequent way. since setting ErrWriter does not change the Logger in any way and also not sets up a new Logger.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, it seems like the right fix would be to make the Clone method do the right thing. This small workaround means (a) that Clone may still be doing the wrong thing in other places and (b) if we make updates to Clone in the future, that may break in this one-off fix here.

downloadErr := runActionWithHooks("download source", terragruntOptionsForDownload, terragruntConfig, func() error {
return downloadSource(terraformSource, terragruntOptions, terragruntConfig)
})
Expand Down
2 changes: 1 addition & 1 deletion configstack/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (stack *Stack) summarizePlanAllErrors(terragruntOptions *options.Terragrunt
)
}
} else if errorStream.Len() > 0 {
terragruntOptions.Logger.Printf("Error with plan: %s", output)
terragruntOptions.Logger.Printf("Error Summary of plan in %s\n%s", stack.Modules[i].Path, output)
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion shell/run_shell_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ func RunShellCommandWithOutput(terragruntOptions *options.TerragruntOptions, wor
// command requested by the user. The output of these other commands should not end up on stdout as this
// breaks scripts relying on terraform's output.
if !reflect.DeepEqual(terragruntOptions.TerraformCliArgs, args) {
outWriter = terragruntOptions.ErrWriter
errWriter = os.Stderr
outWriter = os.Stdout
}

if terragruntOptions.ErrWriter != os.Stderr {
errWriter = io.MultiWriter(terragruntOptions.ErrWriter, os.Stderr)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain the thinking behind these changes a bit more?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is basically taking care of giving a summary of all errors at the end of a plan-all run and printing the errors while running... the check is needed to not print logs twice while running if used in a normal plan (run without being wrapped in a plan-all)..

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the RunShellCommandWithOutput method, which is used in many places in the code base, and not just during plan-all commands. I'm a little concerned about piling up workarounds within RunShellCommandWithOutput that are intended for other methods, as it's not at all obvious why this would be here from just reading this part of the code. Is there some other way to set terragruntOptions params correctly so this method does the right thing without one-off hacks?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed.. ;) i can try to fix it in another way..

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as far as i have seen ErrWriter is not used in a consequent manner and fixing it in a nicer way would require a lot of refactoring as there are already a lot of exceptions throughout the code..

}

if workingDir == "" {
Expand Down