terraform-github-actions

tofu-fmt-check action

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

This action uses the tofu fmt command to check that all files in an OpenTofu 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 OpenTofu files are not formatted correctly.

name: Check file formatting

on: [push]

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

      - name: tofu fmt
        uses: dflook/tofu-fmt-check@v1
        with:
          path: my-tofu-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 OpenTofu file are formatted correctly
    steps:
      - name: Checkout
        uses: actions/checkout@v4

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

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