A GitHub Action that runs terraform plan and posts a formatted comment to your pull request.
This makes it easy for reviewers (who won't have access to run terraform plan) to quickly and easily see what infrastructure changes would be applied by the PR.
Updates existing comments instead of creating duplicates
Collapsible sections for state refresh output
Handles large plans gracefully with truncation
Import support — shows import counts in summary
Multi-directory support via working-directory input (for mono repos)
name: Terraform Plan
on:
pull_request:
branches: [main]
jobs:
plan:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
id-token: write # If using OIDC
steps:
- uses: actions/checkout@v6
# Configure your cloud credentials (example: AWS OIDC)
- uses: aws-actions/configure-aws-credentials@v5
with:
role-to-assume: arn:aws:iam::123456789:role/my-role
aws-region: us-east-2
# Run the plan
- uses: thekbb/terraform-plan-action@v1| Input | Description | Required | Default |
|---|---|---|---|
github-token |
GitHub token for posting PR comments | No | ${{ github.token }} |
working-directory |
Directory containing Terraform configuration | No | . |
terraform-version |
Terraform version to use | No | latest |
setup-terraform |
Whether to setup Terraform (set false if already configured) |
No | true |
init-args |
Additional arguments for terraform init |
No | '' |
plan-args |
Additional arguments for terraform plan |
No | '' |
| Output | Description |
|---|---|
plan-exit-code |
Exit code from terraform plan (0=no changes, 1=error, 2=changes) |
has-changes |
Whether the plan has changes (true/false) |
plan-stdout |
Standard output from terraform plan |
- uses: thekbb/terraform-plan-action@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
terraform-version: '1.14.3'- uses: thekbb/terraform-plan-action@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
working-directory: 'infrastructure/'- uses: thekbb/terraform-plan-action@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
plan-args: '-var-file=prod.tfvars'If you're using a matrix or already have Terraform configured:
- uses: hashicorp/setup-terraform@v3
with:
terraform_version: '1.14.3'
terraform_wrapper: false # Important if capturing output
- uses: thekbb/terraform-plan-action@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
setup-terraform: 'false'The action posts a comment like this:
🔵 import
2· 🟢 create3· 🟡 update1· 🔴 destroy0Terraform used the selected providers to generate the following execution plan...Pusher: @username, Action:
pull_request
For strict environments, pin to a full semantic version or full SHA:
uses: thekbb/terraform-plan-action@<full-commit-sha>See CONTRIBUTING.md for development setup.