Created
July 3, 2026 15:54
-
-
Save rtkaleta/876f04c56556d3ee83da4342f5ef9c2b to your computer and use it in GitHub Desktop.
.github/workflows/terraform-plan.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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