-
-
Notifications
You must be signed in to change notification settings - Fork 539
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fbdd40a
commit e2760ca
Showing
4 changed files
with
77 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,74 @@ | ||
# pre-commit-terraform hook | ||
# Collection of git hooks for Terraform to be used with [pre-commit framework](http://pre-commit.com/) | ||
|
||
[![Github tag](https://img.shields.io/github/tag/antonbabenko/pre-commit-terraform.svg)](https://github.com/antonbabenko/pre-commit-terraform/releases) ![](https://img.shields.io/maintenance/yes/2018.svg) [![Help Contribute to Open Source](https://www.codetriage.com/antonbabenko/pre-commit-terraform/badges/users.svg)](https://www.codetriage.com/antonbabenko/pre-commit-terraform) | ||
|
||
Several [pre-commit](http://pre-commit.com/) hooks to keep Terraform configurations (both `*.tf` and `*.tfvars`) in a good shape: | ||
* `terraform_fmt` - Rewrites all Terraform configuration files to a canonical format. | ||
* `terraform_validate_no_variables` - Validates all Terraform configuration files without checking whether all required variables were set. | ||
* `terraform_validate_with_variables` - Validates all Terraform configuration files and checks whether all required variables were specified. | ||
* `terraform_docs` - Inserts input and output documentation into `README.md`. | ||
## How to install | ||
|
||
## Notes about hooks | ||
### Step 1 | ||
|
||
1. `terraform_validate_no_variables` and `terraform_validate_with_variables` will not work if variables are being set dynamically (eg, when using [Terragrunt](https://github.com/gruntwork-io/terragrunt)). Use `terragrunt validate` command instead. | ||
On MacOSX install the pre-commit package | ||
|
||
```bash | ||
brew install pre-commit | ||
``` | ||
|
||
1. `terraform_docs` will insert/update documentation generated by [terraform-docs](https://github.com/segmentio/terraform-docs) between markers - `<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->` and `<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->` if they are present in `README.md`. Make sure that `terraform-docs` is installed. | ||
For other operating systems check the [official documentation](http://pre-commit.com/#install) | ||
|
||
## Example | ||
### Step 2 | ||
|
||
`.pre-commit-config.yaml`: | ||
Step into the repository you want to have the pre-commit hooks installed and run: | ||
|
||
```yaml | ||
```bash | ||
cat <<EOF > .pre-commit-config.yaml | ||
- repo: git://github.com/antonbabenko/pre-commit-terraform | ||
rev: v1.7.3 | ||
rev: v1.7.4 | ||
hooks: | ||
- id: terraform_fmt | ||
- id: terraform_docs | ||
EOF | ||
``` | ||
|
||
### Step 3 | ||
|
||
Install the pre-commit hook | ||
|
||
```bash | ||
pre-commit install | ||
``` | ||
|
||
### Step 4 | ||
|
||
After pre-commit hook has been installed you can run it manually on all files in the repository | ||
|
||
```bash | ||
pre-commit run -a | ||
``` | ||
|
||
## Available Hooks | ||
|
||
There are several [pre-commit](http://pre-commit.com/) hooks to keep Terraform configurations (both `*.tf` and `*.tfvars`) in a good shape: | ||
* `terraform_fmt` - Rewrites all Terraform configuration files to a canonical format. | ||
* `terraform_validate_no_variables` - Validates all Terraform configuration files without checking whether all required variables were set. | ||
* `terraform_validate_with_variables` - Validates all Terraform configuration files and checks whether all required variables were specified. | ||
* `terraform_docs` - Inserts input and output documentation into `README.md`. Recommended. | ||
* `terraform_docs_without_aggregate_type_defaults` - Inserts input and output documentation into `README.md` without aggregate type defaults. | ||
|
||
Check the [source file](https://github.com/antonbabenko/pre-commit-terraform/blob/master/.pre-commit-hooks.yaml) to know arguments used for each hook. | ||
|
||
## Notes about hooks | ||
|
||
1. `terraform_validate_no_variables` and `terraform_validate_with_variables` will not work if variables are being set dynamically (eg, when using [Terragrunt](https://github.com/gruntwork-io/terragrunt)). Use `terragrunt validate` command instead. | ||
|
||
1. `terraform_docs` and `terraform_docs_without_aggregate_type_defaults` will insert/update documentation generated by [terraform-docs](https://github.com/segmentio/terraform-docs) between markers - `<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->` and `<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->` if they are present in `README.md`. Make sure that `terraform-docs` is installed. | ||
|
||
1. It is possible to pass additional arguments to shell scripts when using `terraform_docs` and `terraform_docs_without_aggregate_type_defaults`. Send pull-request with the new hook if there is something missing. | ||
|
||
Enjoy the clean and documented code! | ||
|
||
## Authors | ||
|
||
This repository is managed by [Anton Babenko](https://github.com/antonbabenko) with help from [these awesome contributors](https://github.com/antonbabenko/pre-commit-terraform/graphs/contributors). | ||
|
||
## License | ||
|
||
MIT licensed. See LICENSE for full details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters