mirror of
https://github.com/tofuutils/pre-commit-opentofu.git
synced 2025-10-15 17:38:54 +02:00
Added followup after #25
This commit is contained in:
parent
fbdd40ac8f
commit
e2760caf8d
4 changed files with 77 additions and 14 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
repos:
|
repos:
|
||||||
- repo: git://github.com/pre-commit/pre-commit-hooks
|
- repo: git://github.com/pre-commit/pre-commit-hooks
|
||||||
rev: v1.2.3
|
rev: v2.0.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: check-yaml
|
- id: check-yaml
|
||||||
- id: end-of-file-fixer
|
- id: end-of-file-fixer
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,15 @@
|
||||||
name: Terraform docs
|
name: Terraform docs
|
||||||
description: Inserts input and output documentation into README.md (using terraform-docs).
|
description: Inserts input and output documentation into README.md (using terraform-docs).
|
||||||
entry: terraform_docs.sh
|
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
|
language: script
|
||||||
files: (\.tf)$
|
files: (\.tf)$
|
||||||
exclude: \.terraform\/.*$
|
exclude: \.terraform\/.*$
|
||||||
|
|
|
||||||
75
README.md
75
README.md
|
|
@ -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/)
|
||||||
|
|
||||||
[](https://github.com/antonbabenko/pre-commit-terraform/releases)  [](https://www.codetriage.com/antonbabenko/pre-commit-terraform)
|
[](https://github.com/antonbabenko/pre-commit-terraform/releases)  [](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_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_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_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
|
## 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_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
|
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.
|
||||||
|
|
||||||
`.pre-commit-config.yaml`:
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
- repo: git://github.com/antonbabenko/pre-commit-terraform
|
|
||||||
rev: v1.7.3
|
|
||||||
hooks:
|
|
||||||
- id: terraform_fmt
|
|
||||||
- id: terraform_docs
|
|
||||||
```
|
|
||||||
|
|
||||||
Enjoy the clean and documented code!
|
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.
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,15 @@
|
||||||
name: Terraform docs
|
name: Terraform docs
|
||||||
description: Inserts input and output documentation into README.md (using terraform-docs).
|
description: Inserts input and output documentation into README.md (using terraform-docs).
|
||||||
entry: terraform_docs.sh
|
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
|
language: script
|
||||||
files: (\.tf)$
|
files: (\.tf)$
|
||||||
exclude: \.terraform\/.*$
|
exclude: \.terraform\/.*$
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue