Giter Site home page Giter Site logo

Comments (13)

Fresa avatar Fresa commented on August 11, 2024 18

According to this post the maximum number of characters in a PR comment is 65536.

I have solved it by always truncating the plan before trying to post it.

- name: Format plan
  id: format-plan
  run: |
    plan=$(cat <<'EOF'
    ${{ format('{0}{1}', steps.plan.outputs.stdout, steps.plan.outputs.stderr) }}
    EOF
    )
    echo "PLAN<<EOF" >> $GITHUB_ENV
    echo "${plan:0:65536}" >> $GITHUB_ENV
    echo "EOF" >> $GITHUB_ENV

from terraform-pr-commenter.

mortizTAG avatar mortizTAG commented on August 11, 2024 1

According to this post the maximum number of characters in a PR comment is 65536.

I have solved it by always truncating the plan before trying to post it.

- name: Format plan
  id: format-plan
  run: |
    plan=$(cat <<'EOF'
    ${{ format('{0}{1}', steps.plan.outputs.stdout, steps.plan.outputs.stderr) }}
    EOF
    )
    echo "PLAN<<EOF" >> $GITHUB_ENV
    echo "${plan:0:65536}" >> $GITHUB_ENV
    echo "EOF" >> $GITHUB_ENV

This worked for me.

from terraform-pr-commenter.

robburger avatar robburger commented on August 11, 2024

Hey @MattiPuolitaivalGKGAB - sorry it's taken so long to get to this issue...it was an interesting one to investigate!

I've just opened an issue actions/runner-images#3257 to see if there's a possibility of changing the underlying GitHub Actions VM.

Unfortunately, if that can't be done, your only option would be to use a self-hosted runner with the stack size bumped up.

from terraform-pr-commenter.

nohhhon avatar nohhhon commented on August 11, 2024

SAM;storage allocation method; command ultra prompt;exe?

from terraform-pr-commenter.

robburger avatar robburger commented on August 11, 2024

@MattiPuolitaivalGKGAB the issue linked above has been merged in the actions repo and new GitHub VM runners have been rolled out this last week.

While I have not tested this, you should be able to pass in a much longer plan now - up to ~16MB of text. The PR commenter will still truncate it anyway here:

CLEAN_PLAN=${CLEAN_PLAN::65300} # GitHub has a 65535-char comment limit - truncate plan, leaving space for comment wrapper
because of the GitHub comment limit...but it should not cause the build to fail anymore.

from terraform-pr-commenter.

m-puolitaival avatar m-puolitaival commented on August 11, 2024

Excellent, thanks @robburger!

from terraform-pr-commenter.

JRo-connyun avatar JRo-connyun commented on August 11, 2024

Hi @robburger,

we unfortunately also ran into this problem today with our plan output of ~3500 rows, which made the job fail. We are running on ubuntu-latest machines and use version 1.4.0 of the terraform-pr-commenter.

Did we overlook something?

from terraform-pr-commenter.

robburger avatar robburger commented on August 11, 2024

Hi @JRo-connyun - I don't think you missed anything. Unfortunately, your plan is probably over the new 16MB input limit on the Actions runner instances (or they're not yet fully rolled out...)

In this case, the best option would be to add a new step after the plan to truncate before sending to the commenter step, like @Fresa has above. With that step above, a new PLAN environment variable becomes available to all steps.

A simpler way might be to use the set-output workflow function. e.g.:

- name: Terraform Plan
  id: plan
  run: terraform plan -out workspace.plan

- name: Truncate Plan
  id: truncate-plan
  run: echo "::set-output name=plan::${${{ format('{0}{1}', steps.plan.outputs.stdout, steps.plan.outputs.stderr) }}:0:65536}"

- name: Post Plan
  if: ...
  uses: robburger/terraform-pr-commenter@v1
  with:
    commenter_type: plan
    commenter_input: ${{ steps.truncate-plan.outputs.plan }}
    commenter_exitcode: ${{ steps.plan.outputs.exitcode }}

☝️ Note: I haven't (yet) tested if this syntax is correct, or will work...

I will test it this weekend and add to the readme. Thanks for raising this again!

from terraform-pr-commenter.

menzenski avatar menzenski commented on August 11, 2024

@robburger for what it's worth, the above does not work for me. The action exits with

Error: The template is not valid. System.InvalidOperationException: Maximum object size exceeded
   at GitHub.DistributedTask.ObjectTemplating.TemplateMemory.AddBytes(Int32 bytes)
   at GitHub.DistributedTask.ObjectTemplating.TemplateMemory.AddBytes(TemplateToken value, Boolean traverse)
   at GitHub.DistributedTask.ObjectTemplating.TemplateUnraveler.AllowScalar(Boolean expand, ScalarToken& scalar)
   at GitHub.DistributedTask.ObjectTemplating.TemplateEvaluator.Evaluate(DefinitionInfo definition)
   at GitHub.DistributedTask.ObjectTemplating.TemplateEvaluator.HandleMappingWithAllLooseProperties(DefinitionInfo mappingDefinition, DefinitionInfo keyDefinition, DefinitionInfo valueDefinition, MappingToken mapping)
   at GitHub.DistributedTask.ObjectTemplating.TemplateEvaluator.Evaluate(DefinitionInfo definition)
   at GitHub.DistributedTask.ObjectTemplating.TemplateEvaluator.Evaluate(TemplateContext context, String type, TemplateToken template, Int32 removeBytes, Nullable`1 fileId, Boolean omitHeader)

I am using these steps:

    - name: Terraform Plan
      id: plan
      if: github.event_name == 'pull_request'
      run: terraform plan

    - name: Truncate Plan
      id: truncate-plan
      run: echo "::set-output name=plan::${${{ format('{0}{1}', steps.plan.outputs.stdout, steps.plan.outputs.stderr) }}:0:65536}"

    - name: Post Plan
      if: always() && github.ref != 'refs/heads/main' && (steps.plan.outcome == 'success' || steps.plan.outcome == 'failure')
      uses: robburger/terraform-pr-commenter@v1
      with:
        commenter_type: plan
        commenter_input: ${{ steps.truncate-plan.outputs.plan }}
        commenter_exitcode: ${{ steps.plan.outputs.exitcode }}

from terraform-pr-commenter.

mortizTAG avatar mortizTAG commented on August 11, 2024

Hi,
I am facing same exact situation, what has the final fix?
Thanks in advance

from terraform-pr-commenter.

aditya-enthu avatar aditya-enthu commented on August 11, 2024

Hello @menzenski, @robburger

Greetings.

Trying this fix but it doesn't seem to trim the plan.
#6 (comment)

Run echo "::set-output name=plan::${
/home/runner/work/_temp/0d83a182-527c-48f2-aa62-e77b6a733bee.sh: line 236: syntax error near unexpected token `('
Error: Process completed with exit code 2.

Using exactly same steps:

      - run: terraform plan -input=false -refresh=false
        id: plan-color
        continue-on-error: true

      - name: Truncate Plan
        id: truncate-plan
        run: echo "::set-output name=plan::${${{ format('{0}{1}', steps.plan-color.outputs.stdout, steps.plan-color.outputs.stderr) }}:0:65536}"

      - name: Post Plan PR comment
        if: steps.plan-color.outcome == 'success' || steps.plan-color.outcome == 'failure'
        uses: robburger/terraform-pr-commenter@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_PERSONAL_TOKEN }}
        with:
          commenter_type: plan
          commenter_input: ${{ steps.truncate-plan.outputs.plan }}
          commenter_exitcode: ${{ steps.plan-color.outputs.exitcode }}

from terraform-pr-commenter.

jsimoni avatar jsimoni commented on August 11, 2024

I am also getting the Argument list too long error when trying to work with a terraform plan that is ~ 7k characters.

from terraform-pr-commenter.

RDhar avatar RDhar commented on August 11, 2024

Building on top of @Fresa (view) and @robburger (view) comments, here's another approach to truncating lengthy Terraform plan outputs which:

  • Retains line breaks in the output variable with EOF for multiline string.
  • Leverages Bash's short-circuit evaluation to return values with echo "${{ this || that }}".
  • Truncates above the last 64800 characters to capture the change summary line (i.e., "Plan: …") and leave room for other text in the comment with tail -c 64800.
  • (Optionally) reduces verbosity by removing lines related to reading/refreshing resources with grep -vE ': Read'

Putting it altogether:

run: |
  { echo "PLAN<<EOF"
    echo "$(echo "${{ steps.terraform_plan.outputs.stderr || steps.terraform_plan.outputs.stdout }}" |
      grep -vE ': Reading...|: Refreshing state...|: Read complete after' |
      tail -c 64800)"
    echo "EOF"
  } >> $GITHUB_ENV

This is part of the packaged solution in DevSecTop/TF-via-PR repository, which hosts a reusable workflow to run Terraform commands via PR comments, like a CLI.

Although it doesn't have all the bells and whistles of terraform-pr-commenter (yet), it's a fair bit quicker; runs Terraform commands simultaneously in bulk; and, dynamically handles Terraform arguments straight from your PR comment input.

Here's an example of the workflow in action and how the output comments are formatted.

from terraform-pr-commenter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.