Comments (13)
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.
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.
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.
SAM;storage allocation method; command ultra prompt;exe?
from terraform-pr-commenter.
@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:
terraform-pr-commenter/entrypoint.sh
Line 188 in c06d8f2
from terraform-pr-commenter.
Excellent, thanks @robburger!
from terraform-pr-commenter.
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.
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.
@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.
Hi,
I am facing same exact situation, what has the final fix?
Thanks in advance
from terraform-pr-commenter.
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.
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.
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)
- Apply
- Comment update removes the wrong comment HOT 2
- Action does not work with Composite action HOT 1
- Read plan from a file?
- Please add an option input to allow or disallow PR comment overwrite
- Docker build error (unable to select packages) HOT 2
- Terraform fmt comment output wrongly with -diff option
- maximum commenter_input length? HOT 2
- update plan comment summary to show changes
- Option to update comments instead of deleting
- Why is it showing this error? It doesn't print the message in the PR HOT 2
- Empty PR comment for plan with "moved"
- Carry through Exit Code HOT 1
- Getting an error for posting the plan in the PR HOT 1
- deprecated messages in plan output are not displayed in the PR
- Multiple environments, not using Terraform workspaces HOT 2
- Is still repository still maintained? HOT 4
- DOES NOT WORK HOT 9
- Error relocating /usr/bin/curl: curl_easy_nextheader: symbol not found? HOT 1
- New Jimdo fork
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from terraform-pr-commenter.