An open API service indexing awesome lists of open source software.

https://github.com/borchero/terraform-plan-comment

GitHub Action to post the output of "terraform plan" to a pull request comment.
https://github.com/borchero/terraform-plan-comment

github-actions terraform

Last synced: about 1 year ago
JSON representation

GitHub Action to post the output of "terraform plan" to a pull request comment.

Awesome Lists containing this project

README

          

# terraform-plan-comment

GitHub Action to post the output of `terraform plan` to a pull request comment.

## Features

- Generate a structured, "markdown-native" representation of the plan
- Obtain a high-level overview via foldable sections
- Do not lose _any_ information compared to the output of `terraform plan`
- Post the plan to pull requests as a "sticky comment"
- Run as a "native" JavaScript action rather than launching a Docker container
- Use with or without the Terraform wrapper script provided by
[hashicorp/setup-terraform](https://github.com/hashicorp/setup-terraform)

## Usage

```yaml
- name: Setup terraform
uses: hashicorp/setup-terraform@v3
- name: Initialize
run: terraform init
- name: Plan
run: terraform plan -out .planfile
- name: Post PR comment
uses: borchero/terraform-plan-comment@v2
with:
token: ${{ github.token }}
planfile: .planfile
```

### Example Comments

Collapsed

Screenshot 2024-04-30 at 00 07 36

Expanded

Screenshot 2024-04-30 at 00 08 22

## Parameters

```yaml
- uses: borchero/terraform-plan-comment@v2
with:
# GitHub token for API access (Required)
token: ""

# Path to the Terraform plan file (Required)
planfile: ""

# Command to execute the Terraform binary
terraform-cmd: terraform

# Directory where Terraform should be called
working-directory: "."

# Header for the PR comment
header: 📝 Terraform Plan

# Skip comments for empty plans
skip-empty: false

# Skip PR comment creation entirely. When enabled, the plan will still be available in the step summary
skip-comment: false
```

### `token` (required)

Required input parameter to access the GitHub API for posting a pull request comment. Can be provided as
`${{ github.token }}`, `${{ env.GITHUB_TOKEN }}` or some personal access token with appropriate permissions.

If using the workflow-provided token, make sure that your workflow/job has write-permissions to pull requests.

### `planfile` (required)

The path to the planfile generated by `terraform plan` which holds the information about which changes ought to be
applied.

### `terraform-cmd`

The command to execute to call the Terraform binary. Defaults to `terraform`. You likely don't need to augment this
unless `terraform` cannot be found in the `PATH`.

### `working-directory`

The directory where the Terraform binary ought to be called. Defaults to `$GITHUB_WORKSPACE` and _must_ be specified if
`terraform init` has been run in a different directory. Should be specified relative to `$GITHUB_WORKSPACE`.

> [!IMPORTANT]
> `planfile` must be specified relative to the working directory.

### `header`

The header that is used for the pull request comment posted by this action. Changing the default allows to distinguish
multiple Terraform runs: each sticky pull request comment is identified by its header.

### `skip-empty`

Whether to skip posting a pull request comment when no changes need to be performed. Defaults to `false`.

### `skip-comment`

Whether to skip posting a pull request comment entirely. When enabled, the plan will still be available in the step
summary.

## Outputs

This action provides the following output:

- `markdown`: The raw markdown output of the terraform plan
- `empty`: Whether the terraform plan contains any change or not