terraform-pr-commenter icon indicating copy to clipboard operation
terraform-pr-commenter copied to clipboard

Comment update removes the wrong comment

Open marcellovictorino opened this issue 3 years ago • 2 comments

This is a great action. Thanks for sharing!

In order to provide a bit more context when running on multiple working directories and environments, I've been using a workaround. Injecting the values of interest into the TF_WORKSPACE env variable.

Which works 👍

- name: >
    Post Plan >> Env: ${{ matrix.project.env }} | Dir: ${{ matrix.project.dir }}
  if: always() && github.ref != 'refs/heads/master' && (steps.plan.outcome == 'success' || steps.plan.outcome == 'failure')
  uses: robburger/terraform-pr-commenter@v1
  env:
    TF_WORKSPACE: ${{ format('Env= {0} | Dir= {1}', matrix.project.env, matrix.project.dir) }}
  with:
    commenter_type: plan
    commenter_input: ${{ format('{0}{1}', steps.plan.outputs.stdout, steps.plan.outputs.stderr) }}
    commenter_exitcode: ${{ steps.plan.outputs.exitcode }}

image


But I noticed that, sometimes, the action incorrectly identifies an "already existing" comment and decides to update it. For example, I have 9 different working-directories / env. But only get 5 PR comments

@robburger Any ideas? How exactly is the "uniqueness" of a comment defined? I imagined that, by adding more detail to the TF_WORKSPACE, it would make it more accurate.

marcellovictorino avatar Nov 08 '21 19:11 marcellovictorino

If you search for the WORKSPACE variable in the script, you can see where it's being used. One thing to notice is that the variable is only used for commenter_type=="plan". This means your workaround will not work for init nor validate.

How exactly is the "uniqueness" of a comment defined?

Have a look at this line. In essence, it filters out the comment containing the string

"### Terraform `plan` .* for Workspace: `'"$WORKSPACE"'`"

JensRantil avatar Feb 15 '23 09:02 JensRantil

This issue is related to #17.

JensRantil avatar Feb 15 '23 09:02 JensRantil