Skip to content

chore: add github action for validating terraform changes #2

chore: add github action for validating terraform changes

chore: add github action for validating terraform changes #2

Workflow file for this run

name: Validate Terraform
on: pull_request
defaults:
run:
working-directory: ./terraform
env:
PM_API_URL: 'https://10.255.0.8:8006/api2/json'
jobs:
build:
permissions:
contents: read
pull-requests: write
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
- name: Terraform fmt
id: fmt
run: |
terraform fmt -check
continue-on-error: true
- name: Terraform init
id: init
run: |
terraform version
terraform init
- name: Terraform validate
id: validate
run: |
terraform validate -no-color
# - name: Terraform Plan
# id: plan
# run: |
# terraform plan -no-color
# continue-on-error: true
- uses: actions/github-script@v7
if: github.event_name == 'pull_request'
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const output = `#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\`
#### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\`
#### Terraform Validation 🤖\`${{ steps.validate.outcome }}\`
<details><summary>Validation Output</summary>
\`\`\`\n
${{ steps.validate.outputs.stdout }}
\`\`\`
</details>
*Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`, Working Directory: \`${{ env.tf_actions_working_dir }}\`, Workflow: \`${{ github.workflow }}\`*`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})