Added followup after #25

This commit is contained in:
Anton Babenko 2018-12-11 20:21:49 +01:00
commit e2760caf8d
4 changed files with 77 additions and 14 deletions

View file

@ -1,6 +1,6 @@
repos:
- repo: git://github.com/pre-commit/pre-commit-hooks
rev: v1.2.3
rev: v2.0.0
hooks:
- id: check-yaml
- id: end-of-file-fixer

View file

@ -10,6 +10,15 @@
name: Terraform docs
description: Inserts input and output documentation into README.md (using terraform-docs).
entry: terraform_docs.sh
args: [--args=--with-aggregate-type-defaults]
language: script
files: (\.tf)$
exclude: \.terraform\/.*$
- id: terraform_docs_without_aggregate_type_defaults
name: Terraform docs (without aggregate type defaults)
description: Inserts input and output documentation into README.md (using terraform-docs).
entry: terraform_docs.sh
language: script
files: (\.tf)$
exclude: \.terraform\/.*$

View file

@ -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:
## How to install
### Step 1
On MacOSX install the pre-commit package
```bash
brew install pre-commit
```
For other operating systems check the [official documentation](http://pre-commit.com/#install)
### Step 2
Step into the repository you want to have the pre-commit hooks installed and run:
```bash
cat <<EOF > .pre-commit-config.yaml
- repo: git://github.com/antonbabenko/pre-commit-terraform
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`.
* `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` 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. `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.
## Example
`.pre-commit-config.yaml`:
```yaml
- repo: git://github.com/antonbabenko/pre-commit-terraform
rev: v1.7.3
hooks:
- id: terraform_fmt
- id: terraform_docs
```
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.

View file

@ -10,6 +10,15 @@
name: Terraform docs
description: Inserts input and output documentation into README.md (using terraform-docs).
entry: terraform_docs.sh
args: [--args=--with-aggregate-type-defaults]
language: script
files: (\.tf)$
exclude: \.terraform\/.*$
- id: terraform_docs_without_aggregate_type_defaults
name: Terraform docs (without aggregate type defaults)
description: Inserts input and output documentation into README.md (using terraform-docs).
entry: terraform_docs.sh
language: script
files: (\.tf)$
exclude: \.terraform\/.*$