Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add working-directory to the comment #17

Open
wolverian opened this issue Jun 29, 2021 · 5 comments
Open

Add working-directory to the comment #17

wolverian opened this issue Jun 29, 2021 · 5 comments
Labels
enhancement New feature or request

Comments

@wolverian
Copy link

wolverian commented Jun 29, 2021

Thank you for the great action! We're running it in production now. 🙂

I have a feature request that would help us: we're running this action for a bunch of modules in one repo, i.e. our repo looks something like this:

root
- vpc
- dns
- eks
- ...etc...

We use an Actions matrix to run the same steps for each directory. This works! 🎉 However, the comment for each init/plan/apply doesn't indicate which module it came from:

Screenshot 2021-06-29 at 10 42 26

This could be fixed by adding the working directory to the message, so it would be e.g. <directory>: Terraform <action> <result> for workspace <workspace>. Another option would be to add the directory to commenter_input, but I haven't tried this yet, as I've assumed that argument should contain only output from Terraform itself.

Does this sound like a sensible feature? Thank you!

@robburger
Copy link
Owner

@wolverian - sorry for the delay, and yes, excellent suggestion!

I recently ran into this problem myself with comments not being deleted due to the title lookup in a matrix run, but the folder problem is also relevant.

@robburger robburger added the enhancement New feature or request label Jul 13, 2021
@MPV
Copy link

MPV commented Oct 21, 2021

As inspiration, https://github.com/iStreamPlanet/github-actions/tree/main/terraform-actions does (or I should say "did", that action seems non-maintained nowadays) the equivalent with a working directory input to the action.

Whichever of the suggested solutions above sound promising (and would be what I'd need in order to switch from iStreamPlanet into this action). ❤️

@marcellovictorino
Copy link

Great suggestion @MPV
As a workaround, I've been using the TF_WORKSPACE variable to keep track of environment and working directory:

- 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 }}

Which looks like this. Not great... not terrible...

image

⚠️ Although, I noticed the action sometimes updates the wrong comment, removing a valid one.

@JensRantil
Copy link

Worth pointing out that the TF_WORKSPACE workaround doesn't work for commenter_type init nor validate - the WORKSPACE variable in the script is only used for commenter_type=="plan". This also needs to be fixed.

@JensRantil
Copy link

JensRantil commented Feb 15, 2023

Inspiration for fixing this: I notice that https://github.com/thollander/actions-comment-pull-request uses a hidden HTML comment to distinguish between comments. That might be a pretty nice implementation. We could also simply delegate the commenting to https://github.com/thollander/actions-comment-pull-request (using a composite action) if we don't want to implement the logic ourselves.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants