Skip to content

Commit

Permalink
Upgraded to work with Terraform >= 0.12 (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
krzyzakp authored and antonbabenko committed Jun 17, 2019
1 parent 9300d0f commit 35e0356
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 45 deletions.
16 changes: 4 additions & 12 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,17 @@

- id: terraform_docs_replace
name: Terraform docs (overwrite README.md)
description: Overwrite content of README.md with terraform-docs
description: Overwrite content of README.md with terraform-docs.
require_serial: true
entry: terraform_docs_replace
language: python
files: (\.tf)$
exclude: \.terraform\/.*$

- id: terraform_validate_no_variables
- id: terraform_validate
name: Terraform validate without variables
description: Validates all Terraform configuration files without checking whether all required variables were set (basic check).
entry: terraform_validate_no_variables.sh
language: script
files: (\.tf|\.tfvars)$
exclude: \.terraform\/.*$

- id: terraform_validate_with_variables
name: Terraform validate with variables
description: Validates all Terraform configuration files and checks whether all required variables were specified.
entry: terraform_validate_with_variables.sh
description: Validates all Terraform configuration files.
entry: terraform_validate.sh
language: script
files: (\.tf|\.tfvars)$
exclude: \.terraform\/.*$
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ pre-commit run -a

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_validate` - Validates all Terraform configuration files.
* `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.
* `terraform_docs_replace` - Runs `terraform-docs` and pipes the output directly to README.md
Expand All @@ -58,8 +57,6 @@ Check the [source file](https://github.com/antonbabenko/pre-commit-terraform/blo

## 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. `terraform_docs_replace` replaces the entire README.md rather than doing string replacement between markers. Put your additional documentation at the top of your `main.tf` for it to be pulled in. The optional `--dest` argument lets you change the name of the file that gets created/modified.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,14 @@ done
for path_uniq in $(echo "${paths[*]}" | tr ' ' '\n' | sort -u); do
path_uniq="${path_uniq//__REPLACED__SPACE__/ }"

pushd "$path_uniq" > /dev/null
if [[ -n "$(find . -maxdepth 1 -name '*.tf' -print -quit)" ]] ; then
if ! terraform validate -check-variables=true ; then
if ! terraform validate $path_uniq; then
error=1
echo
echo "Failed path: $path_uniq"
echo "================================"
fi
fi
popd > /dev/null
done

if [[ "${error}" -ne 0 ]] ; then
Expand Down
26 changes: 0 additions & 26 deletions terraform_validate_no_variables.sh

This file was deleted.

0 comments on commit 35e0356

Please sign in to comment.