robburger / terraform-pr-commenter

A GitHub Action that adds opinionated comments to a PR from Terraform fmt/init/plan output
MIT License
129 stars 63 forks source link

DOES NOT WORK #48

Open gruckion opened 1 year ago

gruckion commented 1 year ago

Doesn't work, I see output saying it will create a comment for the plan but nothing appears.

StefanLobbenmeierObjego commented 1 year ago

Cannot confirm, works in our repo. Maybe there is something wrong with permissions in your workflow?

Edit: broken in my repo as well now, same error as https://github.com/robburger/terraform-pr-commenter/issues/48#issuecomment-1508918376

jcogilvie commented 1 year ago

I have significantly improved this in my fork; the changes can be found in PR #30:

https://github.com/GetTerminus/terraform-pr-commenter

bchrobot commented 1 year ago

FWIW we're seeing this in workflow logs:

Saved the plan to: workspace.plan

To perform exactly these actions, run the following command to apply:
    terraform apply \"workspace.plan\"
" "0"
INFO: Looking for an existing plan PR comment.
Error relocating /usr/bin/curl: curl_easy_nextheader: symbol not found
Error relocating /usr/bin/curl: curl_easy_header: symbol not found
INFO: No existing plan PR comment found.
INFO: Adding plan comment to PR.
Error relocating /usr/bin/curl: curl_easy_nextheader: symbol not found
Error relocating /usr/bin/curl: curl_easy_header: symbol not found

Looks like https://github.com/robburger/terraform-pr-commenter/pull/49 was opened to address that.

No updates to master since 2021 though so we're looking at other forks. Thanks @jcogilvie for highlighting yours.

axdotl commented 1 year ago

@jcogilvie Thanks for providing a fork 🙏🏼

I tried it but unfortunately it fails with

INFO: Found no tfplan.  Proceeding with input argument.
curl: (48) An unknown option was passed in to libcurl

Here is the pipeline snippet

      - name: Comment Plan
        uses: GetTerminus/terraform-pr-commenter@v2
        with:
          commenter_type: plan
          commenter_input: ${{ format('{0}{1}', steps.plan.outputs.stdout, steps.plan.outputs.stderr) }}
          commenter_exitcode: ${{ steps.plan.outputs.exitcode }}
          terraform_version: 1.3.2
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          TF_IN_AUTOMATION: true
          TF_WORKSPACE: ${{ matrix.workspace }}

Do you've an idea what's cause the failing job?

jcogilvie commented 1 year ago

I'll have to update its base image. I think curl has changed out from under it.

jcogilvie commented 1 year ago

Okay, so the most straightforward fix is to use a newer terraform_version since that actually feeds into the image used by the commenter.

I upgraded my workflows to pass in 1.4.5 (as per #49) and it started working again.

axdotl commented 1 year ago

Okay, so the most straightforward fix is to use a newer terraform_version since that actually feeds into the image used by the commenter.

I upgraded my workflows to pass in 1.4.5 (as per #49) and it started working again.

That did the trick 🙏🏼

allexiusw commented 1 year ago

I'm getting the following result:

INFO: Found no tfplan. Proceeding with input argument. INFO: Found 1 page(s) of comments at https://api.github.com/repos/***/tf-infrastructure/issues/3/comments?per_page=100. INFO: Looking for an existing plan PR comment. jq: error (at :4): Cannot index string with string "body" INFO: No existing plan PR comment found. INFO: Found 1 page(s) of comments at https://api.github.com/repos/***/tf-infrastructure/issues/3/comments?per_page=100. INFO: Looking for an existing outputs PR comment. jq: error (at :4): Cannot index string with string "body" INFO: No existing outputs PR comment found. INFO: Writing 1 plan comment(s) INFO: Adding plan comment to PR. INFO: Writing 0 outputs comment(s)

I can not see any comments in my PR,

This is how my gh action looks like:

- name: Apply Terraform
      id: plan
      env:
        ...
      run: |
        terraform init &&
        terraform plan -out workspace.plan
- name: Post Plan
      if: always() && github.ref != 'refs/heads/master'
      uses: GetTerminus/terraform-pr-commenter@v2
      with:
        commenter_type: plan
        commenter_input: ${{ format('{0}{1}', steps.plan.outputs.stdout, steps.plan.outputs.stderr) }}
        commenter_exitcode: ${{ steps.plan.outputs.exitcode }}
        terraform_version: 1.4.5
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        TF_IN_AUTOMATION: true

Any ideas?

rdhar commented 1 year ago

Instead of a pulling a Docker-image every time, I took a stab at this 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 (e.g., -backend-config, -chdir, -var-file, -workspace, -destroy and -auto-approve) straight from your PR comment input.

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