hashicorp / terraform-cdk-action

The Terraform CDK GitHub Action allows you to run CDKTF as part of your CI/CD workflow
Mozilla Public License 2.0
45 stars 18 forks source link

TF Plan output to comment on a PR fails | body is too long (maximum is 65536 characters) #150

Open Gaurav2Github opened 6 months ago

Gaurav2Github commented 6 months ago

Description

I am receiving validation error as below when plan has more than 65536 chars. This occurs when the action tries to add new/update comment after a successful plan on the PR.

Error: Validation Failed: {"resource":"IssueComment","code":"custom","field":"body","message":"body is too long (maximum is 65536 characters)"}

It seems that this 65536 chars is a hard limit https://github.com/orgs/community/discussions/41331 on the Github api.

To mitigate this issue, we should look at trimming the output before trying to add comment or split comments on the PR. Any other suggestion are welcome.

GitHub Action Version

v3.0.3

Configuration

terraformVersion: 1.5.7 cdktfVersion: 0.18.0 stackName: my-tf-stack mode: plan-only terraformCloudToken: ${{ secrets.TF_API_TOKEN }} githubToken: ${{ secrets.GITHUB_TOKEN }}

Gist

No response

Possible Solutions

Trim messageWithTag to first 65536 characters before executing octokit.rest.issues.createComment or octokit.rest.issues.updateComment

Workarounds

Immediate resolution would be to set commentOnPr and updateComment parameters to false temporarily.

Anything Else?

No response

References

No response

Help Wanted

Community Note

Danielku15 commented 6 months ago

Small addition: Currently the whole output is added as comment. Maybe an option to only comment the TF state relevant outputs would be nice. Basically everything between Terraform will perform the following actions: and Plan: # to add, # to change, # to destroy. (in case of a TF plan).

The hundreds of logs "refreshing state..." you might have from your provider are often not much of interest.

github-actions[bot] commented 5 months ago

Hi there! 👋 We haven't heard from you in 30 days and would like to know if the problem has been resolved or if you still need help. If we don't hear from you before then, I'll auto-close this issue in 30 days.

Danielku15 commented 5 months ago

The problem was not resolved and the issue is not stale.

billyjbryant commented 1 week ago

I would opt to trim to the last 65536 characters rather than the first, so you always have the most important portion of the output.

It would also be useful to have an input parameter that when specified, suppresses the cdktf output in the comment and instead links to the workflow's execution summary.

billyjbryant commented 3 days ago

I submitted #212 to fix this issue, would welcome some testing/feedback :)