'terraform plan output too long for GitHub Actions comment

I have the following code that attempts to comment 2 different terraform plan environments on a GitHub pull request:

- name: "Run - Terraform Comment"
  uses: actions/[email protected]
  env:
      STDOUT: |
        ${{ env.terraform1 }}
       
        ${{ env.terraform2 }}
  with:
    github-token: ${{ secrets.GITHUB_TOKEN }}
    script: |
      github.issues.createComment({
        issue_number: context.issue.number,
        owner: context.repo.owner,
        repo: context.repo.repo,
        body: process.env.STDOUT
      })

However, I am getting the following error:

Argument list too long

What is the best practice to possibly reduce the amount of output from terraform plan or a way to instead of commenting the text on the GitHub PR, create a file and link to that?



Solution 1:[1]

If you’re using a Terraform version lower than 0.14, you may want to consider upgrading to 0.14+ as it comes with a new Concise Diff Format that only shows what’s different between your plan and the remote state.

If your plans are still too long, you will probably have to add each plan in a separate comment if you want to view the plans on the PR without opening a separate file.

Worst case scenario, I guess it would be possible for you to create a file with the plans, upload it to something like S3 and then create a link within the PR, but the other two methods would be preferable.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 mpriscella