Skip to content

Commit

Permalink
Initial project source
Browse files Browse the repository at this point in the history
* Adds readme
* Precommit hooks for the project
* Add terraform-fmt hook
  • Loading branch information
mattseymour committed Nov 5, 2020
1 parent 2ae01ec commit 813050f
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 1 deletion.
8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.3.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
8 changes: 8 additions & 0 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
- id: terraform-fmt
name: Terraform fmt (Format)
description: Rewrite all Terraform files (.tf) to canonical format.
entry: ./terraform-fmt.sh
files: (\.tf|\.tfvars)$
# ignore the .terraform directory
exclude: \.terraform\/.*$
language: script
39 changes: 38 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,38 @@
# pre-commit-terraform-fmt
# pre-commit terraform fmt

A pre-commit hook to check the formatting of terraform files pre commit. This hook
requires terraform is present on the system path to work.

It currently does a hard format (changes the state of the files on disk). A future function should
be allowing a `-check` option.

## Installation

Add the following to the `.pre-commit-config.yaml` file.

```
- repo: https://github.com/envelop-risk/pre-commit-terraform-fmt
rev: v1.0.0
hooks:
- id: terraform-fmt
```

The following hooks, while not required are highly recommended.
```
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.3.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
```

## Running the hooks

When first installing the hook it is recommended to run the hook on all files. This can be done
with the command.

```
pre-commit run -a terraform-fmt
```
5 changes: 5 additions & 0 deletions terraform-fmt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

for file in "$@"; do
terraform fmt `dirname $file`
done

0 comments on commit 813050f

Please sign in to comment.