GitHub Action automatically formatting all HCL and TF files (.hcl, .tf, .tfvars).
- Docker Hub: devopsinfra/action-format-hcl:latest
 - GitHub Packages: ghcr.io/devops-infra/action-format-hcl:latest
 
- Container is a stripped down image of my other creation - devopsinfra/docker-terragrunt - framework for managing Infrastructure-as-a-Code.
 - Main use will be everywhere where Terraform or Terragrunt is used.
 - Using combination of my wrapper for cytopia's docker-terragrunt-fmt.
 
Useful in combination with my other action devops-infra/action-commit-push.
This action supports three tag levels for flexible versioning:
vX: latest patch of the major version (e.g.,v1).vX.Y: latest patch of the minor version (e.g.,v1.2).vX.Y.Z: fixed to a specific release (e.g.,v1.2.3).
    - name: Run the Action
      uses: devops-infra/action-format-hcl@v1.0.1
      with:
        list: false
        write: true
        ignore: config
        diff: false
        check: false
        recursive: true
        dir: modules| Input Variable | Required | Default | Description | 
|---|---|---|---|
list | 
No | false | 
List files containing formatting inconsistencies. | 
write | 
No | true | 
Overwrite input files. Should be disabled if using check. | 
ignore | 
No | "" | 
Comma separated list of paths to ignore. Only for .hcl files. | 
diff | 
No | false | 
Display diffs of formatting changes. | 
check | 
No | false | 
Check if files are malformatted. | 
recursive | 
No | true | 
Also process files in subdirectories. | 
dir | 
No | "" | 
Path to be checked. Current dir as default. | 
| Output | Description | 
|---|---|
files_changed | 
List of changed files | 
Action can fail if malformed files will be found.
name: Check HCL
on:
  push
jobs:
  format-hcl:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout
      uses: actions/checkout@v5
    - name: Fail on malformatted files
      uses: devops-infra/action-format-hcl@v1.0.1
      with:
        check: trueAction can automatically format all HCL files and commit updated files back to the repository using my other action action-commit-push.
name: Format HCL
on:
  push
jobs:
  format-hcl:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout
      uses: actions/checkout@v5
    - name: Format HCL files
      uses: devops-infra/action-format-hcl@v1.0.1
    - name: Commit changes to repo
      uses: devops-infra/action-commit-push@v1
      with:
        github_token: ${{ secrets.GITHUB_TOKEN }}
        commit_prefix: "[AUTO-FORMAT-HCL]"Contributions are welcome! See CONTRIBUTING. This project is licensed under the MIT License - see the LICENSE file for details.
This project is licensed under the MIT License - see the LICENSE file for details.
If you have any questions or need help, please:
- π Create an issue
 - π Star this repository if you find it useful!