Skip to content

Commit

Permalink
update after PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-halliday committed Nov 3, 2023
1 parent d119e33 commit 42d470d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 96 deletions.
14 changes: 1 addition & 13 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,7 @@
description: Runs all terraform tests
entry: hooks/terraform_test.sh
language: script
files: (\.tf)$
exclude: \.terraform\/.*$

- id: terragrunt_test
name: Terragrunt test
description: Runs all terraform tests
entry: hooks/terragrunt_test.sh
language: script
<<<<<<< HEAD
files: (\.tf)$d
=======
files: (\.tf)$
>>>>>>> c943481 (Add terraform and terragrunt testing)
files: (\.tf|\.tfvars|\.terraform\.lock\.hcl||\.terraform\.lock\.hcl||\.terraform\.lock\.json)$
exclude: \.terraform\/.*$

- id: terragrunt_validate
Expand Down
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ If you are using `pre-commit-terraform` already or want to support its developme
* [terraform\_docs\_replace (deprecated)](#terraform_docs_replace-deprecated)
* [terraform\_fmt](#terraform_fmt)
* [terraform\_providers\_lock](#terraform_providers_lock)
* [terraform\_test](#terraform_test)
* [terraform\_tflint](#terraform_tflint)
* [terraform\_tfsec](#terraform_tfsec)
* [terraform\_validate](#terraform_validate)
Expand Down Expand Up @@ -271,9 +272,10 @@ There are several [pre-commit](https://pre-commit.com/) hooks to keep Terraform
| `terraform_docs_without_`<br>`aggregate_type_defaults` | Inserts input and output documentation into `README.md` without aggregate type defaults. Hook notes same as for [terraform_docs](#terraform_docs) | `terraform-docs` |
| `terraform_fmt` | Reformat all Terraform configuration files to a canonical format. [Hook notes](#terraform_fmt) | - |
| `terraform_providers_lock` | Updates provider signatures in [dependency lock files](https://www.terraform.io/docs/cli/commands/providers/lock.html). [Hook notes](#terraform_providers_lock) | - |
| `terraform_test` | Runs any Terraform Tests, which requires Terraform 1.6 and above. [Hook notes](#terraform_test) |
| `terraform_tflint` | Validates all Terraform configuration files with [TFLint](https://github.com/terraform-linters/tflint). [Available TFLint rules](https://github.com/terraform-linters/tflint/tree/master/docs/rules#rules). [Hook notes](#terraform_tflint). | `tflint` |
| `terraform_tfsec` | [TFSec](https://github.com/aquasecurity/tfsec) static analysis of terraform templates to spot potential security issues. [Hook notes](#terraform_tfsec) | `tfsec` |
| `terraform_validate` | Validates all Terraform configuration files. [Hook notes](#terraform_validate) | `jq`, only for `--retry-once-with-cleanup` flag |
| `terraform_validate` sd | Validates all Terraform configuration files. [Hook notes](#terraform_validate) | `jq`, only for `--retry-once-with-cleanup` flag |
| `terragrunt_fmt` | Reformat all [Terragrunt](https://github.com/gruntwork-io/terragrunt) configuration files (`*.hcl`) to a canonical format. | `terragrunt` |
| `terragrunt_validate` | Validates all [Terragrunt](https://github.com/gruntwork-io/terragrunt) configuration files (`*.hcl`) | `terragrunt` |
| `terraform_wrapper_module_for_each` | Generates Terraform wrappers with `for_each` in module. [Hook notes](#terraform_wrapper_module_for_each) | `hcledit` |
Expand Down Expand Up @@ -645,6 +647,24 @@ To replicate functionality in `terraform_docs` hook:
- --tf-init-args=-upgrade
```

### terraform_test

1. `terraform_test` supports custom arguments so you can set the test directory, set a variable file, change output to JSON and change the verbosity, filtering which tests runs, and set individual variables.

Example:

```yaml
- id: terraform_test
args:
- --args=-test-directory=path
- --arg=-filter=testfile
- --args=-json
- --arg=-verbose
- --arg=-var-file=filename
- --arg=-var=variable
```

2. `terraform_test` only runs per repository.

### terraform_tflint

Expand Down
18 changes: 3 additions & 15 deletions hooks/terraform_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,12 @@ function main {
}

#######################################################################
# Unique part of `common::per_dir_hook`. The function is executed in loop
# on each provided dir path. Run wrapped tool with specified arguments
# Unique part of `common::per_dir_hook`. The function is executed one time
# in the root git repo
# Arguments:
# dir_path (string) PATH to dir relative to git repo root.
# Can be used in error logging
# change_dir_in_unique_part (string/false) Modifier which creates
# possibilities to use non-common chdir strategies.
# Availability depends on hook.
# args (array) arguments that configure wrapped tool behavior
# Outputs:
# If failed - print out hook checks status
#######################################################################
function per_dir_hook_unique_part {
# shellcheck disable=SC2034 # Unused var.
local -r dir_path="$1"
# shellcheck disable=SC2034 # Unused var.
local -r change_dir_in_unique_part="$2"
shift 2
function run_hook_on_whole_repo {
local -a -r args=("$@")

# pass the arguments to hook
Expand Down
67 changes: 0 additions & 67 deletions hooks/terragrunt_test.sh

This file was deleted.

0 comments on commit 42d470d

Please sign in to comment.