Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgraded to work with Terraform >= 0.12 #44

Merged
merged 3 commits into from
Jun 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.