Skip to content
upload-cloud

GitHub Action

GitHub Action for formating HCL files

v0.3.6 Latest version

GitHub Action for formating HCL files

upload-cloud

GitHub Action for formating HCL files

GitHub Action automatically formatting all HCL and TF files

Installation

Copy and paste the following snippet into your .yml file.

              

- name: GitHub Action for formating HCL files

uses: devops-infra/action-format-hcl@v0.3.6

Learn more about this action in devops-infra/action-format-hcl

Choose a version

GitHub Action for formating HCL files

GitHub Action automatically formatting all HCL and TF files (.hcl, .tf, .tfvars).

Dockerized as devopsinfra/action-format-hcl.

Features:

Badge swag

Master branch Other branches
GitHub repo GitHub code size in bytes GitHub last commit GitHub license
DockerHub Docker version Image size Docker Pulls

Reference

    - name: Fail on malformatted files
      uses: devops-infra/action-format-hcl@v0.3.6
      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. 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.

Examples

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@v2
    - name: Fail on malformatted files
      uses: devops-infra/action-format-hcl@v0.3.6
      with:
        check: true

Action 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@v2
    - name: Format HCL files
      uses: devops-infra/action-format-hcl@v0.3.6
    - name: Commit changes to repo
      uses: devops-infra/action-commit-push@master
      with:
        github_token: ${{ secrets.GITHUB_TOKEN }}
        commit_prefix: "[AUTO-FORMAT-HCL]"