mirror of
https://github.com/tofuutils/pre-commit-opentofu.git
synced 2025-10-15 17:38:54 +02:00
Upgraded to work with Terraform >= 0.12 (#44)
This commit is contained in:
parent
9300d0f194
commit
35e0356188
5 changed files with 35 additions and 74 deletions
|
|
@ -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\/.*$
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
declare -a paths
|
||||
index=0
|
||||
|
||||
for file_with_path in "$@"; do
|
||||
file_with_path="${file_with_path// /__REPLACED__SPACE__}"
|
||||
|
||||
paths[index]=$(dirname "$file_with_path")
|
||||
(( "index+=1" ))
|
||||
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=false ; then
|
||||
echo
|
||||
echo "Failed path: $path_uniq"
|
||||
echo "================================"
|
||||
fi
|
||||
fi
|
||||
popd > /dev/null
|
||||
done
|
||||
Loading…
Add table
Add a link
Reference in a new issue