Skip to content

Instantly share code, notes, and snippets.

@rtkaleta
Created July 3, 2026 15:54
Show Gist options
  • Select an option

  • Save rtkaleta/876f04c56556d3ee83da4342f5ef9c2b to your computer and use it in GitHub Desktop.

Select an option

Save rtkaleta/876f04c56556d3ee83da4342f5ef9c2b to your computer and use it in GitHub Desktop.
.github/workflows/terraform-plan.yml
name: Terraform Plan Commenter
on:
pull_request:
branches: [ "main" ]
jobs:
terraform-plan:
name: 'Terraform Plan'
runs-on: ubuntu-latest
env:
# You need to add this to your GitHub repository secrets
TF_API_TOKEN: ${{ secrets.TF_API_TOKEN }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }}
- name: Terraform Init
id: init
run: terraform init
- name: Terraform Plan
id: plan
run: terraform plan -no-color
continue-on-error: true
- name: Post Plan to PR Comment
uses: actions/github-script@v7
if: github.event_name == 'pull_request'
env:
PLAN: "terraform\n${{ steps.plan.outputs.stdout }}"
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const output = `#### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\`
#### Terraform Plan 📖\`${{ steps.plan.outcome }}\`
<details><summary>Show Plan</summary>
\`\`\`\n
${process.env.PLAN}
\`\`\`
</details>`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment