terraform-github-actions

terraform-fmt action

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

This action uses the terraform 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 Terraform file formatting

on:
  push:
    branches:
      - main

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

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