Skip to content

Commit

Permalink
chore: add terraform fmt check (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
lechnerc77 authored Jun 2, 2024
1 parent 3287072 commit f6cf7bd
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/terraform_format_check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Terraform Format Check

on:
pull_request:
types:
- opened
- reopened
- synchronize
- ready_for_review
workflow_dispatch:

jobs:
# Retrive the changed directories from the PR
terraform-fmt:
name: Validate format of Terraform files
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_wrapper: false

- name: Get changed directories
id: changed-files
uses: tj-actions/changed-files@v44
with:
dir_names: 'true'

- name: Validate Terraform format
if: steps.changed-files.outputs.any_changed == 'true'
env:
ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
shell: bash
run: |
EXIT_CODE=0
for file in ${ALL_CHANGED_FILES}; do
echo "Checking format of $file with terraform fmt"
terraform fmt -check -recursive "$file" || EXIT_CODE=$?
done
exit $EXIT_CODE

0 comments on commit f6cf7bd

Please sign in to comment.