Giter Site home page Giter Site logo

terraform-pr-commenter's Introduction

Terraform PR Commenter

Adds opinionated comments to PR's based on Terraform fmt, init, plan and validate outputs.

Summary

This Docker-based GitHub Action is designed to work in tandem with hashicorp/setup-terraform with the wrapper enabled, taking the output from a fmt, init, plan or validate, formatting it and adding it to a pull request. Any previous comments from this Action are removed to keep the PR timeline clean.

The terraform_wrapper needs to be set to true (which is already the default) for the hashicorp/setup-terraform step as it enables the capturing of stdout, stderr and the exitcode.

Support (for now) is limited to Linux as Docker-based GitHub Actions can only be used on Linux runners.

Usage

This action can only be run after a Terraform fmt, init, plan or validate has completed, and the output has been captured. Terraform rarely writes to stdout and stderr in the same action, so we concatenate the commenter_input:

- uses: robburger/terraform-pr-commenter@v1
  env:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  with:
    commenter_type: fmt/init/plan/validate # Choose one
    commenter_input: ${{ format('{0}{1}', steps.step_id.outputs.stdout, steps.step_id.outputs.stderr) }}
    commenter_exitcode: ${{ steps.step_id.outputs.exitcode }}

Inputs

Name Requirement Description
commenter_type required The type of comment. Options: [fmt, init, plan, validate]
commenter_input required The comment to post from a previous step output.
commenter_exitcode required The exit code from a previous step output.

Environment Variables

Name Requirement Description
GITHUB_TOKEN required Used to execute API calls. The ${{ secrets.GITHUB_TOKEN }} already has permissions, but if you're using your own token, ensure it has the repo scope.
TF_WORKSPACE optional Default: default. This is used to separate multiple comments on a pull request in a matrix run.
EXPAND_SUMMARY_DETAILS optional Default: true. This controls whether the comment output is collapsed or not.
HIGHLIGHT_CHANGES optional Default: true. This switches ~ to ! in plan diffs to highlight Terraform changes in orange. Set to false to disable.

All of these environment variables can be set at job or step level. For example, you could collapse all outputs but expand on a plan:

jobs:
  terraform:
    name: 'Terraform'
    runs-on: ubuntu-latest
    env:
      EXPAND_SUMMARY_DETAILS: 'false' # All steps will have this environment variable
    steps:
      - name: Checkout
        uses: actions/checkout@v2
...
      - name: Post Plan
        uses: robburger/terraform-pr-commenter@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          EXPAND_SUMMARY_DETAILS: 'true' # Override global environment variable; expand details just for this step
        with:
          commenter_type: plan
          commenter_input: ${{ format('{0}{1}', steps.plan.outputs.stdout, steps.plan.outputs.stderr) }}
          commenter_exitcode: ${{ steps.plan.outputs.exitcode }}
...

Examples

Single workspace build, full example:

name: 'Terraform'

on:
  pull_request:
  push:
    branches:
      - master

jobs:
  terraform:
    name: 'Terraform'
    runs-on: ubuntu-latest
    env:
      GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      TF_IN_AUTOMATION: true
    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Setup Terraform
        uses: hashicorp/setup-terraform@v1
        with:
          cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }}
          terraform_version: 0.15.0

      - name: Terraform Format
        id: fmt
        run: terraform fmt -check -recursive
        continue-on-error: true

      - name: Post Format
        if: always() && github.ref != 'refs/heads/master' && (steps.fmt.outcome == 'success' || steps.fmt.outcome == 'failure')
        uses: robburger/terraform-pr-commenter@v1
        with:
          commenter_type: fmt
          commenter_input: ${{ format('{0}{1}', steps.fmt.outputs.stdout, steps.fmt.outputs.stderr) }}
          commenter_exitcode: ${{ steps.fmt.outputs.exitcode }}

      - name: Terraform Init
        id: init
        run: terraform init

      - name: Post Init
        if: always() && github.ref != 'refs/heads/master' && (steps.init.outcome == 'success' || steps.init.outcome == 'failure')
        uses: robburger/terraform-pr-commenter@v1
        with:
          commenter_type: init
          commenter_input: ${{ format('{0}{1}', steps.init.outputs.stdout, steps.init.outputs.stderr) }}
          commenter_exitcode: ${{ steps.init.outputs.exitcode }}

      - name: Terraform Validate
        id: validate
        run: terraform validate

      - name: Post Validate
        if: always() && github.ref != 'refs/heads/master' && (steps.validate.outcome == 'success' || steps.validate.outcome == 'failure')
        uses: robburger/terraform-pr-commenter@v1
        with:
          commenter_type: validate
          commenter_input: ${{ format('{0}{1}', steps.validate.outputs.stdout, steps.validate.outputs.stderr) }}
          commenter_exitcode: ${{ steps.validate.outputs.exitcode }}

      - name: Terraform Plan
        id: plan
        run: terraform plan -out workspace.plan

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

      - name: Terraform Apply
        id: apply
        if: github.ref == 'refs/heads/master' && github.event_name == 'push'
        run: terraform apply workspace.plan

Multi-workspace matrix/parallel build:

...
jobs:
  terraform:
    name: 'Terraform'
    runs-on: ubuntu-latest
    strategy:
      matrix:
        workspace: [audit, staging]
    env:
      GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      TF_IN_AUTOMATION: true
      TF_WORKSPACE: ${{ matrix['workspace'] }}
    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Setup Terraform
        uses: hashicorp/setup-terraform@v1
        with:
          cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }}
          terraform_version: 0.15.0

      - name: Terraform Init - ${{ matrix['workspace'] }}
        id: init
        run: terraform init

      - name: Post Init - ${{ matrix['workspace'] }}
        if: always() && github.ref != 'refs/heads/master' && (steps.init.outcome == 'success' || steps.init.outcome == 'failure')
        uses: robburger/terraform-pr-commenter@v1
          with:
            commenter_type: init
            commenter_input: ${{ format('{0}{1}', steps.init.outputs.stdout, steps.init.outputs.stderr) }}
            commenter_exitcode: ${{ steps.init.outputs.exitcode }}

      - name: Terraform Plan - ${{ matrix['workspace'] }}
        id: plan
        run: terraform plan -out ${{ matrix['workspace'] }}.plan

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

"What's the crazy-looking if: doing there?" Good question! It's broken into 3 logic groups separated by &&, so all need to return true for the step to run:

  1. always() - ensures that the step is run regardless of the outcome in any previous steps. i.e. We don't want the build to quit after the previous step before we can write a PR comment with the failure reason.
  2. github.ref != 'refs/heads/master' - prevents the step running on a master branch. PR comments are not possible when there's no PR!
  3. (steps.step_id.outcome == 'success' || steps.step_id.outcome == 'failure') - ensures that this step only runs when step_id has either a success or failed outcome.

In English: "Always run this step, but only on a pull request and only when the previous step succeeds or fails...and then stop the build."

Screenshots

fmt

fmt

init

fmt

plan

fmt

validate

fmt

Troubleshooting & Contributing

Feel free to head over to the Issues tab to see if the issue you're having has already been reported. If not, open a new one and be sure to include as much relevant information as possible, including code-samples, and a description of what you expect to be happening.

License

MIT

terraform-pr-commenter's People

Contributors

adefossez-zenika avatar gotoeveryone avatar robburger avatar xinluh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

terraform-pr-commenter's Issues

Apply

Is it possible to get the output from an apply? I'd very much like it to write a comment on the pull request when it's done applying

Action does not work with Composite action

Once again, thanks for this great Action!

Since the steps are repetitive, quite verbose and with clear parameters, I wanted to encapsulate it within a GitHub composite action.

I managed to work around its current limitations -i.e. not supporting the continue-on-error functionality.
But the action just did not post a comment. Not even mentioned: "this is not a PR..."

@robburger
❓ Am I missing something?
I would love to use this "composite" version in my workflows.


.github/actions/terraform_comment_pr/actions.yml

name: 'Terraform Comment PR'
description: 'Init, Plan and Apply TF projects, commenting Plan output onto PR'
inputs:
  deploymentDirectory:  # id of input
    description: 'the directory of the terraform project'
    required: true
  env:  # id of input
    description: 'the deployment environment'
    required: true
  workspaceEnv:  # id of input
    description: 'the deployment WORKSPACE environment to be activated'
    required: true

runs:
  using: "composite"
  steps:
    - uses: hashicorp/setup-terraform@v1
      with:
        terraform_version: 0.14.5

    - name: >
        Terraform Init >> Env: ${{ inputs.env }} | Dir: ${{ inputs.deploymentDirectory }}
      shell: bash
      run: |
        cd ${{ inputs.deploymentDirectory }}
        terraform init -backend=true -backend-config=environment/${{ inputs.env }}/backend-config.tfvars
        terraform workspace new ${{ inputs.workspaceEnv }} || terraform workspace select ${{ inputs.workspaceEnv }}  

    - name: >
        Terraform Plan >> Env: ${{ inputs.env }} | Dir: ${{ inputs.deploymentDirectory }}
      id: plan
      shell: bash
      run: |
        cd ${{ inputs.deploymentDirectory }}
        # Workaround continue-on-error not being supported
        terraform plan -var-file environment/${{ inputs.env }}/environment.tfvars -detailed-exitcode \
        || echo "::set-output name=exitcode_continue_on_error::$?"

    - name: >
        Post Plan >> Env: ${{ inputs.env }} | Dir: ${{ inputs.deploymentDirectory }}
      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}', inputs.env, inputs.deploymentDirectory) }}
      with:
        commenter_type: plan
        commenter_input: ${{ format('{0}{1}', steps.plan.outputs.stdout, steps.plan.outputs.stderr) }}
        commenter_exitcode: ${{ steps.plan.outputs.exitcode }}

    - name: Raise error if plan.exitcode == 1
      if: steps.plan.outputs.exitcode == 1
      shell: bash
      run: exit 1

    - name: >
        Terraform Apply >> Env: ${{ inputs.env }} | Dir: ${{ inputs.deploymentDirectory }}
      if: steps.plan.outputs.exitcode == 2 
      shell: bash
      run: |
        cd ${{ inputs.deploymentDirectory }}
        terraform apply -var-file environment/${{ inputs.env }}/environment.tfvars -input=false -auto-approve

And the actual workflow would look like this:

- name: Terraform Comment PR
  uses: ./.github/actions/terraform_comment_pr
  with:
    deploymentDirectory: ${{ matrix.project.dir }}
    env:  ${{ matrix.project.env }}
    workspaceEnv: ${{ env.ENV }} 

Terraform fmt comment output wrongly with -diff option

Hi,
When using -diff option for terraform fmt, the comment in PR looks weird. Thanks for looking into this.

image

      - name: Terraform Format
        id: fmt
        run: terraform -chdir=${{ env.working_directory}} fmt -check -recursive -diff
        continue-on-error: true

      - name: Post Format Result
        if: always() && github.event_name == 'pull_request' && (steps.fmt.outcome == 'success' || steps.fmt.outcome == 'failure')
        uses: robburger/terraform-pr-commenter@v1.5.0
        with:
          commenter_type: fmt
          commenter_input: ${{ format('{0}{1}', steps.fmt.outputs.stdout, steps.fmt.outputs.stderr) }}
          commenter_exitcode: ${{ steps.fmt.outputs.exitcode }}

Error relocating /usr/bin/curl: curl_easy_nextheader: symbol not found?

The robburger/terraform-pr-commenter@v1 workflow was function properly for me for some time.

Recently, I noticed that it cannot write comments to GitHub Pull Request.

Found the following error under robburger/terraform-pr-commenter@v1 workflow.

Releasing state lock. This may take a few moments...
" "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

Plan truncates "Changes to Outputs:"

The recent change in commit 53de913 to the way the plan truncation happens cuts off the Changes to Outputs: section, which follows the Plan: x to add, x to change, x to destroy. line.

Fix: have a look at the horizontal rule characters again and try to truncate before them.

Error: Argument list too long

Hi!

First of all, thanks for the great tool. Been using it for few days and really digging it.

I'm trying to publish a plan output of a larger environment, but I get an error "Error: Argument list too long". The plan output is around ~2800 rows long.

Docker build error (unable to select packages)

I ran into the following error, so I will share the situation.
version: v1.5.0

Step 3/6 : RUN apk add --no-cache -q     bash     curl     jq
   ---> Running in ae6d5c417541
    bash (no such package):
  ERROR: unable to select packages:
      required by: world[bash]
    curl (no such package):
      required by: world[curl]
    jq (no such package):
      required by: world[jq]
The command '/bin/sh -c apk add --no-cache -q     bash     curl     jq' returned a non-zero code: 3
  Warning: Docker build failed with exit code 3, back off 5.943 seconds before retry.

It looks like an error happened in Docker build step because it is unable to install the package.

Multiple environments, not using Terraform workspaces

Hi!

We have multiple environments but are not using workspaces. Instead, we use the "separate directories" strategy. However, we would still like to get separate PR comments for each environments's plan.

Am I correct in that a workaround is we can still rely on the TF_WORKSPACE environment (and set it only for the robburger/terraform-pr-commenter@v1 action) to make sure we get separate PR comments?

Why is it showing this error? It doesn't print the message in the PR

Terraform will perform the following actions:
  # module.backend.google_project.this[\"example-tf\"] will be created
  + resource \"google_project\" \"this\" {
      + auto_create_network = false
      + billing_account     = \"foobar\"
      + id                  = (known after apply)
      + labels              = {
          + \"terraform\" = \"example\"
        }
      + name                = \"Example TF\"
      + number              = (known after apply)
      + org_id              = \"foobar[52](https://github.com/bancodebogota/bbog-ca-gcp-organizations-iac/runs/6833095425?check_suite_focus=true#step:15:53)29649\"
      + project_id          = \"example-tf\"
      + skip_delete         = (known after apply)
    }
Plan: 1 to add, 0 to change, 0 to destroy.
" "0"
INFO: Looking for an existing plan PR comment.
jq: error (at <stdin>:4): Cannot index string with string "body"
INFO: No existing plan PR comment found.
INFO: Adding plan comment to PR.

Getting an error for posting the plan in the PR

Plan: 2 to add, 0 to change, 0 to destroy.

─────────────────────────────────────────────────────────────────────────────

Saved the plan to: tfplan

To perform exactly these actions, run the following command to apply:
    terraform apply \"tfplan\"
" "0"
INFO: Looking for an existing plan PR comment.
curl: (16) Error in the HTTP2 framing layer
INFO: No existing plan PR comment found.
INFO: Adding plan comment to PR.
curl: (16) Error in the HTTP2 framing layer
- name: Post Plan
  if: always() && github.ref != 'refs/heads/master' && (steps.plan.outcome == 'success' || steps.plan.outcome == 'failure')
  uses: robburger/terraform-pr-commenter@v1
  with:
    commenter_type: plan
    commenter_input: ${{ format('{0}{1}', steps.plan.outputs.stdout, steps.plan.outputs.stderr) }}
    commenter_exitcode: ${{ steps.plan.outputs.exitcode }}
  env:
   GITHUB_TOKEN: ${{ secrets.GOOGLE_CREDENTIALS }}

Am I missing something?

update plan comment summary to show changes

It would be great if the summary for the plan action would show the top-line changes, so the information could be more glanceable, like below:

53 to add, 155 to change, 53 to destroy.
FULL_PLAN_HERE

Or:

No changes. Infrastrcture up to date.
FULL_PLAN_HERE

This could be done by grepping the text for the right strings:

SUMMARY = grep -E '(to add|No changes)'

Comment update removes the wrong comment

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.

Please add an option input to allow or disallow PR comment overwrite

Can an additional (optional) input be created e.g.:

  allow_pr_override:
    description: '(Optional) Allow existing comments on PR to be overridden.'
    required: false
    type: boolean
    default: true 

The reason this would be handy is because I do automated tests on a single workspace "default", but my tests involves using terraform plan, to plan and apply a build, and then after on the same PR I also do a terraform plan --destroy and then apply a destroy.

Because my initial plan which shows the build, the second plan (destroy plan) overrides the build plan on the PR, I would like this not to happen as I want to see both comments on the same PR for my build plan as well as my destroy plan as the test involves a build apply plan as well as a destroy apply plan.

The build plan will be commented as expected, but when my workflow reaches the destroy plan step, the existing build plan comment will be overriden and thus I end up only seeing the destroy plan on the PR comments.

I want this override to be configurable on the inputs on this action if possible. if the setting is false, I want the action to just add another comment on the same PR, and if the setting is true, it can override:

image

At the moment it only and always will override.

Carry through Exit Code

Hi, thanks for such a useful action!

After trying this out, I'm a little confused on how to properly fail the workflow job if one of the terraform steps fail.

We're passing continue-on-error: true to the terraform step, like the example shows. It seems the commenter step(s) should exit non-zero after posting the comment as to stop processing subsequent job steps, but the commenter exits zero even when it was handed a non-zero from the terraform wrapper.

I feel like I'm missing something obvious but the readme states

In English: "Always run this step, but only on a pull request and only when the previous step succeeds or fails...and then stop the build.

What trigger should be used stop the build?

Thanks again!

Lines that starts with a hyphen are interpretated as "Removed"

At least that's what I think is causing the following issue.
Left is the output from Terraform Plan.
Right is the comment generated in the PR by the terraform-pr-commenter action.

image

Each line that starts with either the Terraform Remove hyphen sign or a yaml hyphen indicating a list item are highlighted in the comment as being removed.

I have blanked some values that contained "sensitive" information.

Download action repository 'robburger/terraform-pr-commenter@v1'
v1 is currently v1.3.0
0.14.9: Pulling from hashicorp/terraform

deprecated messages in plan output are not displayed in the PR

Deprecated messages such as this in the terraform plan:

Warning: Argument is deprecated

  with module.terraform-module-account.aws_s3_bucket.aman,
  on .terraform/modules/terraform-module-account/aman.tf line 9, in resource "aws_s3_bucket" "aman":
   9:   acl           = "private"

Use the aws_s3_bucket_acl resource instead

are not displayed in the PR.

Can the messages be captured and displayed please.

Read plan from a file?

Sometimes our plans get quite lengthy if we make a core level change that fans out. In these cases, we get "argument list too long" errors in docker. Would it be possible to add support for passing a plan file reference to the commenter rather than the raw comment text, and have the commenter script cat the file itself?

Better support for Terraform v1.x

If using Terraform v1.x and a plan produces no output, the comment on the timeline is empty.

Terraform v1.0 introduced additional possible outputs for plan, so more regexing is needed to catch all "stories".

Used to be: No changes. Infrastructure is up-to-date.
Now: No changes. Your infrastructure matches the configuration.

maximum commenter_input length?

I started getting the following error
Error: An error occurred trying to start process '/usr/bin/docker' with working directory '/home/runner/work/...'. Argument list too long
with

      - name: Terragrunt Plan
        id: plan
        if: github.event_name == 'pull_request'
        run: terragrunt run-all plan -no-color --terragrunt-non-interactive
        continue-on-error: true

      - name: Post Plan
        uses: robburger/[email protected]
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          EXPAND_SUMMARY_DETAILS: 'true' # Override global environment variable; expand details just for this step
        with:
          commenter_type: plan
          commenter_input: ${{ format('{0}{1}', steps.plan.outputs.stdout, steps.plan.outputs.stderr) }}
          commenter_exitcode: ${{ steps.plan.outputs.exitcode }}

I was able to work around it by truncating the plan to 65535 characters before sending it to terraform-pr-commenter, but what is the maximum string length we can send to terraform-pr-commenter as I feel that is where the issue is? The terraform-pr-commenter code should properly truncate the string down to 65300 characters

  if [[ $EXIT_CODE -eq 0 || $EXIT_CODE -eq 2 ]]; then
    CLEAN_PLAN=$(echo "$INPUT" | sed -r '/^(An execution plan has been generated and is shown below.|Terraform used the selected providers to generate the following execution|No changes. Infrastructure is up-to-date.|No changes. Your infrastructure matches the configuration.|Note: Objects have changed outside of Terraform)$/,$!d') # Strip refresh section
    CLEAN_PLAN=$(echo "$CLEAN_PLAN" | sed -r '/Plan: /q') # Ignore everything after plan summary
    CLEAN_PLAN=${CLEAN_PLAN::65300} # GitHub has a 65535-char comment limit - truncate plan, leaving space for comment wrapper
    CLEAN_PLAN=$(echo "$CLEAN_PLAN" | sed -r 's/^([[:blank:]]*)([-+~])/\2\1/g') # Move any diff characters to start of line
    if [[ $COLOURISE == 'true' ]]; then
      CLEAN_PLAN=$(echo "$CLEAN_PLAN" | sed -r 's/^~/!/g') # Replace ~ with ! to colourise the diff in GitHub comments
    fi

although it would be nice to merge pull request #25 to give an indication that the plan was truncated/referenced elsewhere.

DOES NOT WORK

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

Add working-directory to the comment

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!

Getting `There must be an exit code from a previous step.` error

My workflow looks like this

      - run: |
          terraform init
          terraform plan -out tfplan
        id: plan
      - uses: robburger/terraform-pr-commenter@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          commenter_type: plan
          commenter_input: ${{ format('{0}{1}', steps.plan.outputs.stdout, steps.plan.outputs.stderr) }}
          commenter_exitcode: ${{ steps.plan.outputs.exitcode }}

Earlier I was using Makefile, I thought if it is doing something with exit code, So I had replaced make plan by the current multiline command which does terraform init and terraform plan but it doesn't seem to solve the issue.

Terraform version I'm using is 0.14.10

- uses: hashicorp/setup-terraform@v1
        with:
          terraform_version: 0.14.10
          terraform_wrapper: false

Empty PR comment for plan with "moved"

Below is plan output for which PR comment is empty.

Terraform will perform the following actions:

  # aws_security_group_rule.core_to_xxxhas moved to aws_security_group_rule.core_to_xxx[0]
    resource "aws_security_group_rule" "core_to_xxx" {
        id                = "sgrule-00000"
        # (9 unchanged attributes hidden)
    }

Plan: 0 to add, 0 to change, 0 to destroy.

Plan with changes on terraform 0.15 do not display anything

CLEAN_PLAN=$(echo "$INPUT" | sed -r '/^(An execution plan has been generated and is shown below.|No changes. Infrastructure is up-to-date.)$/,$!d') # Strip refresh section

Hello, i've upgraded my terraform to 0.15, and it seems that i can't see my changes, because the sentence has changed, on terraform's side.

ex on 0.15 :

Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

VS on 0.13, for example :

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

We can see the "An execution plan has been generated and is shown below." has disappear.

Maybe we can fix the regex to catch both sentences ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.