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: Add an output option to filter output for custom run steps #3518

Merged
merged 4 commits into from
Jun 30, 2023

Conversation

mightyguava
Copy link
Contributor

@mightyguava mightyguava commented Jun 13, 2023

what

Add an output argument to the run step used for custom commands that can post-process command output. Allows you to do something like

    plan:
      steps:
        - run:
            command: terragrunt plan -out $PLANFILE --terragrunt-ignore-external-dependencies
            output: strip_refreshing
        - run: terragrunt show -json $PLANFILE > $SHOWFILE

which will filter out Refreshing state... lines similar to how it's done when using the default terraform plan steps.

The valid options for output are:

  • show - the default, current behavior of echoing the output
  • hide - hide the output for the entire command. Useful for setup steps whose output isn't useful to show in the posted plan comment. Theoretically for the example above, it can be used for the terragrunt plan step, and then adding another terrarunt show step that outputs the plan in human-readable form.
  • strip_refreshing - runs the StripRefreshingFromPlanOutput that currently runs for the default plan action

Alternatively, I also considered adding a different (or composable) option to run an arbitrary command to filter. E.g. maybe an outputFilter option that accepts a shell command similar to command. It would receive in stdin the full output of the run command to do arbitrary filtering on. Decided not to though since it'd be a bit more complex and may not really be needed.

Please let me know if this is a reasonable approach, and if so I'll polish it up and add docs!

why

This significantly reduces the verbosity of the plan output posted in PR comments for workflows that use custom commands, letting these workflows match the behavior of the default plan action.

There is a potential workaround per #3386 (comment), but doing so hides the filtered output from real-time streaming logs as well. The user would have no way of seeing these filtered out log lines even if they wanted to.

tests

Tested by running the unit tests and running in a real AWS account set up using terragrunt. The strip_refreshing option configured above works as expected, omitting everything before the last "Refreshing state..." marker :

Before this PR
Initializing the backend...

Successfully configured the backend "s3"! Terraform will automatically
use this backend unless the backend configuration changes.

Initializing provider plugins...
- Finding hashicorp/aws versions matching ">= 2.49.0"...
- Installing hashicorp/aws v5.3.0...
- Installed hashicorp/aws v5.3.0 (signed by HashiCorp)

Terraform has created a lock file .terraform.lock.hcl to record the provider
selections it made above. Include this file in your version control repository
so that Terraform can guarantee to make the same selections by default when
you run "terraform init" in the future.

Terraform has been successfully initialized!
aws_route53_zone.this["<REDACTED>"]: Refreshing state... [id=<REDACTED>]
aws_route53_zone.this["<REDACTED>"]: Refreshing state... [id=<REDACTED>]

Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
  - destroy

Terraform will perform the following actions:

... truncated ...
After this PR
Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
  - destroy

Terraform will perform the following actions:

... truncated ...

The hide option also works as expected, completely hiding the output for the step it is set for.

references

@mightyguava mightyguava requested a review from a team as a code owner June 13, 2023 23:46
@github-actions github-actions bot added the go Pull requests that update Go code label Jun 13, 2023
@mightyguava mightyguava changed the title Add an output option to filter output for custom run steps feat: Add an output option to filter output for custom run steps Jun 13, 2023
@mightyguava
Copy link
Contributor Author

hi @runatlantis/maintainers, is anyone available to review this PR?

GenPage
GenPage previously approved these changes Jun 29, 2023
Copy link
Member

@GenPage GenPage left a comment

Choose a reason for hiding this comment

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

I think this is perfect for now. A very clean and scoped approach. There is no need to run arbitrary commands and I'm hesitant to overload custom workflows that much.

@GenPage
Copy link
Member

GenPage commented Jun 29, 2023

Please polish and add docs. I'll merge once complete.

@GenPage GenPage added feature New functionality/enhancement quick-win Is obviously something Atlantis should do and will take <4 hrs work labels Jun 29, 2023
@GenPage GenPage added this to the v0.25.0 milestone Jun 29, 2023
@github-actions github-actions bot added the docs Documentation label Jun 29, 2023
@mightyguava
Copy link
Contributor Author

Here's the updated docs. I changed the formatting a bit on the env one to be consistent too.

image image

@GenPage GenPage merged commit a6161c9 into runatlantis:main Jun 30, 2023
mtavaresmedeiros pushed a commit to mtavaresmedeiros/atlantis that referenced this pull request Jul 3, 2023
…unatlantis#3518)

* feat: Add an `output` option to filter output for custom run steps
@jmreicha
Copy link
Contributor

I saw this missed v0.25.0. Is there any estimate on when this will be released?

@mightyguava
Copy link
Contributor Author

@jmreicha This was included in both v0.24.4 and v0.25.0. Not sure how it escaped the changelog though.

@jmreicha
Copy link
Contributor

Ah, good deal. Thanks for the clarification!

@jamengual
Copy link
Contributor

jamengual commented Aug 12, 2023 via email

ijames-gc pushed a commit to gocardless/atlantis that referenced this pull request Feb 13, 2024
…unatlantis#3518)

* feat: Add an `output` option to filter output for custom run steps
ijames-gc pushed a commit to gocardless/atlantis that referenced this pull request Feb 13, 2024
…unatlantis#3518)

* feat: Add an `output` option to filter output for custom run steps
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation feature New functionality/enhancement go Pull requests that update Go code quick-win Is obviously something Atlantis should do and will take <4 hrs work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Atlantis output in GitHub PRs unexpectedly showing "Initializing backend..." and "Refreshing state..."
4 participants