learn-terraform-github-actions
learn-terraform-github-actions copied to clipboard
If the plan is large then the step to comment it fails
Error: An error occurred trying to start process '/home/runner/runners/2.294.0/externals/node16/bin/node' with working directory '/home/runner/work/REPO_NAME/REPO_NAME'. Argument list too long
This step:
- uses: actions/github-script@v6
if: github.event_name == 'pull_request'
env:
PLAN: "terraform\n${{ steps.plan.outputs.stdout }}"
@mission-lblaney do you have any update on this? I am trying to run my Actions too.
@mission-lblaney I found this info related to this issue mentioned by you:
- https://github.community/t/maximum-length-for-the-comment-body-in-issues-and-pr/148867
This has been working for my organization for some months now.
- name: Terraform Plan without varFile specified
run: |
terraform plan -out=plan.tfplan
continue-on-error: true
- name: Uncolored Terraform Plan for Bot
if: github.event_name == 'pull_request'
id: plan
run: |
terraform show -no-color plan.tfplan >${GITHUB_WORKSPACE}/plan.out
terraform show -no-color -json plan.tfplan >${GITHUB_WORKSPACE}/plan.json
continue-on-error: true
- name: Terraform PR commands Info
if: github.event_name == 'pull_request'
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const run_url = process.env.GITHUB_SERVER_URL + '/' + process.env.GITHUB_REPOSITORY + '/actions/runs/' + process.env.GITHUB_RUN_ID
const run_link = '<a href="' + run_url + '">Actions</a>.'
const fs = require('fs')
const plan_file = fs.readFileSync('plan.out', 'utf8')
const plan = plan_file.length > 65000 ? plan_file.toString().substring(0, 65000) + " ..." : plan_file
const truncated_message = plan_file.length > 65000 ? "Output is too long and was truncated. You can read full Plan in " + run_link + "<br /><br />" : ""
const output = `#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\`
#### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\`
#### Terraform Validation 🤖\`${{ steps.validate.outputs.outcome }}\`
#### Terraform Plan 📖\`${{ steps.plan.outcome }}\`
<details><summary>Show Plan</summary>
\`\`\`hcl\n
${plan}
\`\`\`
</details>
${truncated_message}
*Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`, Workflow: \`${{ github.workflow }}\`*`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})