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

Request: less verbose plan summary output #131

Closed
skpy opened this issue Aug 26, 2021 · 5 comments
Closed

Request: less verbose plan summary output #131

skpy opened this issue Aug 26, 2021 · 5 comments

Comments

@skpy
Copy link
Contributor

skpy commented Aug 26, 2021

The terraform plan -no-color step produces a lot of output: setup, refreshing state, etc:

terraform
Running plan in the remote backend. Output will stream here. Pressing Ctrl-C
will stop streaming the logs, but will not stop the plan running remotely.

Preparing the remote plan...

The remote workspace is configured to work with configuration at
/ relative to the target repository.

Terraform will upload the contents of the following directory,
excluding files or directories as defined by a .terraformignore file
at /home/runner/work/terraform-workspaces/terraform-workspaces/.terraformignore (if it is present),
in order to capture the filesystem context the remote workspace expects:
    /home/runner/work/terraform-workspaces/terraform-workspaces

To view this run in a browser, visit:
https://app.terraform.io/app/organization/terraform-workspaces/runs/run-ID...

Waiting for the plan to start...

Terraform v1.0.5
on linux_amd64
Configuring remote state backend...
Initializing Terraform configuration...
random_id.random: Refreshing state... [id=AmoEhmlP3G4]
tfe_workspace.dev: Refreshing state... [id=ws-3jagXYEb6u2NHmZp]
tfe_workspace.demo: Refreshing state... [id=ws-PrkfhaX62FWkqpSS]
tfe_variable.random_id: Refreshing state... [id=var-BLGnDF4w8TrJB1Lb]
tfe_variable.aws_default_region: Refreshing state... [id=var-YkMUSuu2snnWSncK]
tfe_variable.region: Refreshing state... [id=var-uNC45eAsPcx5fx4j]
tfe_variable.environment: Refreshing state... [id=var-8rZAAuV3DNfQvGur]
tfe_variable.aws_access_key: Refreshing state... [id=var-ephG9K2xdDQ2Rf1j]
tfe_variable.cluster_version: Refreshing state... [id=var-1uFBu5NLpefBdUGi]
tfe_variable.cluster_name: Refreshing state... [id=var-eBADc8EZVj2LdXRU]
tfe_variable.aws_secret_key: Refreshing state... [id=var-pXyvjfAqNThTQv19]

Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # tfe_variable.cluster_version will be updated in-place
  ~ resource "tfe_variable" "cluster_version" {
        id           = "var-1uFBu5NLpefBdUGi"
      ~ value        = (sensitive value)
        # (6 unchanged attributes hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.


------------------------------------------------------------------------

Cost estimation:

Resources: 0 of 2 estimated
           $0.0/mo +$0.0

The majority of that is uninteresting in the normal course of work, and results in a lot of text that humans are going to skim over. What is interesting (for us!) is from Terraform will perform the following actions: to the end. I tried, briefly, to capture the output and pass it through additional Actions steps to grep and tail just the relevant (to us) bits, but failed pretty spectacularly.

I could try modifying the plan step to use -out=path to create a file, parse that file, and emit that in a subsequent step. Before I go that route, might there exist some prior art for this that I can use? Or might it make sense to create such a summary output example for others to follow in the future?

@anovis
Copy link

anovis commented Sep 27, 2021

any update on this?

@scalaster
Copy link

I did this as plan 2>/dev/null | grep 'Plan:' or plan 2>/dev/null | grep 'No changes' to get a single line output. There could be a more elegant approach I suppose

@RYFN
Copy link

RYFN commented Feb 28, 2023

I've lifted the grep command here hashicorp/terraform#27214 (comment)

Into a separate step, then I use the github env variable in the comment step. I found piping plan directly to grep resulted in a bunch of debug output I didn't want. There's probably a nicer way to do this without the temp file!

      - name: Plan Infra Changes
        id: plan
        run: |
          terraform plan -no-color -input=false

      - name: Tidy Plan output
        run : |
          echo "${{ steps.plan.outputs.stdout }}" | grep -v "Refreshing state...\|Reading...\|Read complete after" > plan-out.txt
          cat plan-out.txt
          echo 'PLAN_OUTPUT<<EOF' >> $GITHUB_ENV
          echo "$(cat plan-out.txt)" >> $GITHUB_ENV
          echo 'EOF' >> $GITHUB_ENV
       
      - name: Update Pull Request
        uses: actions/github-script@v6
        if: github.event_name == 'pull_request'
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          script: |

            ... (per example in README)

            <details><summary>Show Plan</summary>

            \`\`\`\n
            ${{ env.PLAN_OUTPUT }}
            \`\`\`

            </details>`;

            ...(snip)

Screenshot 2023-02-28 at 15 53 27

@bflad
Copy link
Contributor

bflad commented Nov 29, 2023

Hi folks 👋 The intended purpose of this GitHub Action is to install Terraform and optionally configure parts of its CLI configuration file. We do not intend to support manipulating the output from Terraform commands via this action, so therefore I'm going to close this issue. Terraform issues such as hashicorp/terraform#27214 can be followed to track this sort of feature request. If you have further questions about manipulating the output from Terraform commands, you can submit a topic in the Terraform section of HashiCorp Discuss.

@bflad bflad closed this as not planned Won't fix, can't repro, duplicate, stale Nov 29, 2023
Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants