This GitHub Action reads changes from your Terraform plan JSON output, summarizes the changes, and posts them in a single GitHub Pull Request comment.
We recommend using this in your Infrastructure as Code delivery workflow to make any change visible and acclerate the PR review process.
Implementing this Action is super simple and the comments are consise and easy to read. Other implementations may be heavily opinionated or require adding multiple jobs to your workflow.
- Display changes in a Terraform plan without posting larger sections of the plan change log. This approach will, in most cases, avoid the situation where plan contents are too large for a single PR comment.
- Collapsed as a summary by default, when expanded, the comment is broken up into sections for deletion, creation, and resource changes. The changes are also color-coded to help draw attention to each proposed modification.
- This JavaScript GitHub Action runs directly on a host runner and executes faster than a Docker container Action.
- Possibility to add the output to your workflow summary.
- Possibility to hide previous comments generated by this action.
- Possibility to not create any comments in case there are no infrastructure changes.
- Customize the header and the footer of the generated output.
Optional Defaults to tfplan.json
-
The location of the JSON file created by running
terraform show -no-color -json tfplan.plan > tfplan.json
(Or whatever you choose to name your plan or json outputs) -
Multiple files can be provided using a text block.
Optional Boolean defaults to ${{github.token}}
- Used to authenticate with the GitHub API.
Optional Boolean defaults to false
- Will expand the changes in comments by default rather than having them collapsed beneath the summary
Optional Defaults to false
-
Will write the plan output to the workflow summary.
-
The workflow summary will still be set when running this action outside of a PR context.
Optional Defaults to Terraform Plan Changes
- Will set the header of the PR comment and/or workflow summary.
Optional Defaults to ""
- Will set a footer of the PR comment and/or workflow summary.
Optional Defaults to false
- Will include a link back to the workflow in the PR comment and/or workflow summary.
Optional Defaults to false
- Will not create a PR comment when there are no infrastructure changes.
Optional Defaults to false
- Will hide/minimize all previous comments generated by this action.
Optional Defaults to true
- Logs all the changed resources found in the plan to the action output.
Single plan file:
uses: liatrio/[email protected]
with:
json-file: my-tfplan.json
expand-comment: 'true'
Multiple plan files:
uses: liatrio/[email protected]
with:
json-file: |
core-infra-tfplan.json
shared-infra-tfplan.json
Include plan output to the Actions workflow job summary:
uses: liatrio/[email protected]
with:
json-file: my-tfplan.json
expand-comment: 'true'
include-plan-job-summary: 'true'
Note:
- When
include-plan-job-summary = true
, if the action is executed in non-Pull Request workflows, the plan output will also be posted to the job summary of that run. If you do not wish to have this behavior, apply conditional logic to your workflow file.
To use this action with OpenTofu you need to initialize OpenTofu without the wrapper, like discussed in the known issues
below.
You also need to convert the planfile to a JSON planfile using the tofu show -json
command.
- uses: opentofu/setup-opentofu@v1
with:
tofu_wrapper: false
- name: Create planfile
run: tofu plan -no-color -out=./.planfile
- name: Convert planfile to JSON planfile
run: tofu show -json ./.planfile >> ./my-planfile.json
- name: Create PR comment
uses: liatrio/[email protected]
with:
json-file: my-planfile.json
Known issue when including the Terraform Wrapper script
- Execution may error with
Error: Unexpected token c in JSON at position 1
- Cause: Terraform wrapper enabled (default behavior) causes invalid JSON in Terraform output.
- Fix: Exclude the Terraform Wrapper when setting up Terraform (GitHub Actions example)
- name: Setup Terraform uses: hashicorp/setup-terraform@v2 with: terraform_wrapper: false
If you'd like to suggest changes, feel free to submit a Pull Request or open an issue.
Otherwise if things aren't working as expected, please open a new issue. Please include code references, a description of the issue, and expected behavior.