terraform-github-actions

tofu-fmt action

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

This action uses the tofu fmt -recursive command to reformat files in a directory into a canonical format.

Inputs

Environment Variables

Example usage

This example automatically creates a pull request to fix any formatting problems that get merged into the main branch.

name: Fix OpenTofu file formatting

on:
  push:
    branches:
      - main

jobs:
  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@v1
        with:
          path: my-tofu-config

      - name: Create Pull Request
        uses: peter-evans/create-pull-request@v5
        with:
          commit-message: tofu fmt
          title: Reformat tofu files
          body: Update OpenTofu files to canonical format using `tofu fmt`
          branch: automated-tofu-fmt