terraform-github-actions

terraform-fmt-check action

This is one of a suite of Terraform related actions - find them at dflook/terraform-github-actions.

This action uses the terraform fmt command to check that all files in a Terraform configuration directory are in the canonical format. This can be used to check that files are properly formatted before merging.

If any files are not correctly formatted a failing GitHub check will be added for the file, and the job failed.

Inputs

Outputs

Environment Variables

Example usage

This example workflow runs on every push and fails if any of the Terraform files are not formatted correctly.

name: Check file formatting

on: [push]

jobs:
  check_format:
    runs-on: ubuntu-latest
    name: Check Terraform file are formatted correctly
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: terraform fmt
        uses: dflook/terraform-fmt-check@v1
        with:
          path: my-terraform-config

This example executes a run step only if the format check failed.

name: Check file formatting

on: [push]

jobs:
  check_format:
    runs-on: ubuntu-latest
    name: Check Terraform file are formatted correctly
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: terraform fmt
        uses: dflook/terraform-fmt-check@v1
        id: fmt-check
        with:
          path: my-terraform-config

      - name: Wrong formatting found
        if: $
        run: echo "formatting check failed"