https://github.com/devops-infra/action-format-hcl
GitHub Action automatically formatting all HCL and TF files
https://github.com/devops-infra/action-format-hcl
automation christophshyper ci-cd cicd devops devops-workflow docker dockerhub github-action github-action-docker github-actions github-actions-docker hcl hcl-files hcl2 hclfmt iaac terraform terragrunt
Last synced: 5 months ago
JSON representation
GitHub Action automatically formatting all HCL and TF files
- Host: GitHub
- URL: https://github.com/devops-infra/action-format-hcl
- Owner: devops-infra
- License: mit
- Created: 2020-04-03T16:48:04.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2024-11-18T18:51:13.000Z (6 months ago)
- Last Synced: 2024-11-18T19:46:02.283Z (6 months ago)
- Topics: automation, christophshyper, ci-cd, cicd, devops, devops-workflow, docker, dockerhub, github-action, github-action-docker, github-actions, github-actions-docker, hcl, hcl-files, hcl2, hclfmt, iaac, terraform, terragrunt
- Language: Dockerfile
- Homepage: https://christophshyper.github.io/
- Size: 183 KB
- Stars: 9
- Watchers: 3
- Forks: 2
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# GitHub Action for formating HCL files
**GitHub Action automatically formatting all [HCL](https://github.com/hashicorp/hcl) and [TF](https://www.terraform.io/docs/configuration/index.html) files (.hcl, .tf, .tfvars).**
Dockerized as [devopsinfra/action-format-hcl](https://hub.docker.com/repository/docker/devopsinfra/action-format-hcl).
Features:
* Container is a stripped down image of my other creation - [devopsinfra/docker-terragrunt](https://github.com/devopsinfra/docker-terragrunt) - framework for managing Infrastructure-as-a-Code.
* Main use will be everywhere where [Terraform](https://github.com/hashicorp/terraform) or [Terragrunt](https://github.com/gruntwork-io/terragrunt) is used.
* Using combination of my wrapper for [cytopia](https://github.com/cytopia)'s [docker-terragrunt-fmt](https://github.com/cytopia/docker-terragrunt-fmt).## Badge swag
[](https://github.com/devops-infra/action-format-hcl/actions?query=workflow%3A%22Master+branch%22)
[](https://github.com/devops-infra/action-format-hcl/actions?query=workflow%3A%22Other+branches%22)
[




](https://github.com/devops-infra/action-format-hcl "shields.io")
[




](https://hub.docker.com/r/devopsinfra/action-format-hcl "shields.io")## Reference
```yaml
- name: Fail on malformatted files
uses: devops-infra/[email protected]
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.
```yaml
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/[email protected]
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](https://github.com/devops-infra/action-commit-push).
```yaml
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/[email protected]
- name: Commit changes to repo
uses: devops-infra/action-commit-push@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
commit_prefix: "[AUTO-FORMAT-HCL]"
```