|
1 | 1 | # terraform-plan-comment |
2 | 2 |
|
3 | 3 | GitHub Action to post the output of `terraform plan` to a PR comment. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- Generate a "markdown-native" representation of the plan including foldable sections and coloring |
| 8 | +- Post the plan to pull requests as a "sticky comment" |
| 9 | +- Use with or without the Terraform wrapper script provided by |
| 10 | + [hashicorp/setup-terraform](https://github.com/hashicorp/setup-terraform) |
| 11 | + |
| 12 | +## Usage |
| 13 | + |
| 14 | +```yaml |
| 15 | +- name: Setup terraform |
| 16 | + uses: hashicorp/setup-terraform@v3 |
| 17 | +- name: Initialize |
| 18 | + run: terraform init |
| 19 | +- name: Plan |
| 20 | + run: terraform plan -out .planfile |
| 21 | +- name: Post PR comment |
| 22 | + uses: borchero/terraform-plan-comment@v1 |
| 23 | + with: |
| 24 | + token: ${{ github.token }} |
| 25 | + planfile: .planfile |
| 26 | +``` |
| 27 | +
|
| 28 | +### Example Comments |
| 29 | +
|
| 30 | +<details><summary><b>Collapsed</b></summary> |
| 31 | +
|
| 32 | +<img width="916" alt="Screenshot 2024-04-30 at 00 07 36" src="https://github.com/borchero/terraform-plan-comment/assets/22455425/b6d0e64c-1c9c-42b8-8060-c096922baa0a"> |
| 33 | +
|
| 34 | +</details> |
| 35 | +
|
| 36 | +<details><summary><b>Expanded</b></summary> |
| 37 | +
|
| 38 | +<img width="699" alt="Screenshot 2024-04-30 at 00 08 22" src="https://github.com/borchero/terraform-plan-comment/assets/22455425/c91c319a-276d-4d2d-98a7-52bd24b64d4c"> |
| 39 | +
|
| 40 | +</details> |
| 41 | +
|
| 42 | +## Parameters |
| 43 | +
|
| 44 | +This action provides a few input parameters that allow for customization: |
| 45 | +
|
| 46 | +### `token` (required) |
| 47 | + |
| 48 | +Required input parameter to access the GitHub API for posting a pull request comment. Can be provided as |
| 49 | +`${{ github.token }}`, `${{ env.GITHUB_TOKEN }}` or some personal access token with appropriate permissions. |
| 50 | + |
| 51 | +If using the workflow-provided token, make sure that your workflow/job has write-permissions to pull requests. |
| 52 | + |
| 53 | +### `planfile` (required) |
| 54 | + |
| 55 | +The path to the planfile generated by `terraform plan` which holds the information about which changes ought to be |
| 56 | +applied. |
| 57 | + |
| 58 | +### `terraform-cmd` |
| 59 | + |
| 60 | +The command to execute to call the Terraform binary. Defaults to `terraform`. You likely don't need to augment this |
| 61 | +unless `terraform` cannot be found in the `PATH`. |
| 62 | + |
| 63 | +### `working-directory` |
| 64 | + |
| 65 | +The directory where the Terraform binary ought to be called. Defaults to `$GITHUB_WORKSPACE` and _must_ be specified if |
| 66 | +`terraform init` has been run in a different directory. Should be specified relative to `$GITHUB_WORKSPACE`. |
| 67 | + |
| 68 | +> [!IMPORTANT] > `planfile` must be specified relative to the working directory. |
| 69 | + |
| 70 | +### `id` |
| 71 | + |
| 72 | +A custom identifier for the Terraform execution. This allows to distinguish multiple Terraform runs: each sticky pull |
| 73 | +request comment is tied to an ID. |
0 commit comments