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

feat: -detailed-exitcode with run-all commands #3585

Merged
merged 3 commits into from
Nov 21, 2024

Conversation

levkohimins
Copy link
Contributor

@levkohimins levkohimins commented Nov 21, 2024

Description

Fixes #1470.

For the case where a run-all is done with -detailed-exitcode flag, Terragrunt uses the following logic to return the appropriate exit code:

  • If any unit throws a 1, throw a 1.
  • If any unit throws a 2, but nothing throws a 1, throw a 2.
  • If nothing throws a non-zero, throw a 0.

TODOs

Read the Gruntwork contribution guidelines.

  • Update the docs.
  • Run the relevant tests successfully, including pre-commit checks.
  • Ensure any 3rd party code adheres with our license policy or delete this line if its not applicable.
  • Include release notes. If this PR is backward incompatible, include a migration guide.

Release Notes (draft)

Added / Removed / Updated [X].

Migration Guide

@levkohimins levkohimins marked this pull request as ready for review November 21, 2024 14:35
yhakbar
yhakbar previously approved these changes Nov 21, 2024
Copy link
Collaborator

@yhakbar yhakbar left a comment

Choose a reason for hiding this comment

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

LGTM.

I think we need to have some documentation for indicating how this works. In a follow-up PR, could we add some notes to the run-all docs indicating that when using the -detailed-exitcode, Terragrunt will use information aggregated from all the runs to determine the final exit code, and how?

)

const (
DetailedExitCodeNoChanges int = iota
Copy link
Member

Choose a reason for hiding this comment

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

Unused constant 'DetailedExitCodeNoChanges'

const (
DetailedExitCodeNoChanges int = iota
DetailedExitCodeError
DetailedExitCodeChangesPresent
Copy link
Member

Choose a reason for hiding this comment

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

Unused constant 'DetailedExitCodeChangesPresent'

grep -irn "DetailedExitCodeChangesPresent" .
./shell/detailed_exitcode.go:10:        DetailedExitCodeChangesPresent
./test/integration_test.go:130:func TestDetailedExitCodeChangesPresentAll(t *testing.T) {
./test/integration_test.go:148:func TestDetailedExitCodeChangesPresentOne(t *testing.T) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed unused.


_, _, err := helpers.RunTerragruntCommandWithOutputWithContext(t, ctx, "terragrunt run-all plan --terragrunt-log-level debug --terragrunt-non-interactive -detailed-exitcode --terragrunt-working-dir "+rootPath)
require.NoError(t, err)
require.Equal(t, 2, exitCode.Get())
Copy link
Member

Choose a reason for hiding this comment

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

hm, afaik, erorrs are checked with require., other checks are through assert.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@denis256
Copy link
Member

Failed on pre-commit on fmt for terraform files

Terraform fmt............................................................Failed
- hook id: terraform-fmt
- exit code: 3

@levkohimins
Copy link
Contributor Author

LGTM.

I think we need to have some documentation for indicating how this works. In a follow-up PR, could we add some notes to the run-all docs indicating that when using the -detailed-exitcode, Terragrunt will use information aggregated from all the runs to determine the final exit code, and how?

Sure, thanks. Could you please indicate where exactly in the documents this should be mentioned? Here?

@levkohimins
Copy link
Contributor Author

Failed on pre-commit on fmt for terraform files

Terraform fmt............................................................Failed
- hook id: terraform-fmt
- exit code: 3

Fixed

@yhakbar
Copy link
Collaborator

yhakbar commented Nov 21, 2024

Sure, thanks. Could you please indicate where exactly in the documents this should be mentioned? Here?

Ya. I'll write it up, though. Don't worry about it.

I'm seeing that this can also be worded better:

[WARNING] Using run-all with plan is currently broken for certain use cases...

@levkohimins levkohimins merged commit 88a99ad into main Nov 21, 2024
4 of 5 checks passed
@levkohimins levkohimins deleted the feat/detailed-exitcode branch November 21, 2024 19:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Question] - How to use -detailed-exitcode with terragrunt plan
3 participants