Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: George L. Yermulnik <[email protected]>
  • Loading branch information
MaxymVlasov and yermulnik authored Nov 25, 2022
1 parent 537c49f commit b52b475
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -663,14 +663,15 @@ Example:
- --hook-config=--retry-once-with-cleanup=true # Boolean. true or false
```

> Note: That flag require additional installed dependency: `jq`.
> Note: The flag requires additional dependency to be installed: `jq`.

If `--retry-once-with-cleanup=true`, then in each failed directory the cached modules and providers from the `.terraform` directory will be deleted, before retrying once more. To avoid unnecessary deletion of this directory, the cleanup and retry will only happen if Terraform produces any of the following error messages:

* Missing or corrupted provider plugins
* Module source has changed
* Module version requirements have changed
* Module not installed
* "Missing or corrupted provider plugins"
* "Module source has changed"
* "Module version requirements have changed"
* "Module not installed"
* "Could not load plugin"

**Warning:** When using `--retry-once-with-cleanup=true`, problematic `.terraform/modules/` and `.terraform/providers/` directories will be recursively deleted without prompting for consent. Other files and directories will not be affected, such as the `.terraform/environment` file.

Expand All @@ -690,7 +691,7 @@ Example:

`terraform_validate` hook will try to reinitialize them before running the `terraform validate` command.

**Warning:** If you use Terraform workspaces, DO NOT use this option ([details](https://github.com/antonbabenko/pre-commit-terraform/issues/203#issuecomment-918791847)). Consider the first option, or wait to [`force-init`](https://github.com/antonbabenko/pre-commit-terraform/issues/224) option implementation.
**Warning:** If you use Terraform workspaces, DO NOT use this option ([details](https://github.com/antonbabenko/pre-commit-terraform/issues/203#issuecomment-918791847)). Consider the first option, or wait for [`force-init`](https://github.com/antonbabenko/pre-commit-terraform/issues/224) option implementation.

4. `terraform_validate` in a repo with Terraform module, written using Terraform 0.15+ and which uses provider `configuration_aliases` ([Provider Aliases Within Modules](https://www.terraform.io/language/modules/develop/providers#provider-aliases-within-modules)), errors out.

Expand Down
4 changes: 2 additions & 2 deletions hooks/terraform_validate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ function per_dir_hook_unique_part {
validate_errors_matched=$?

# Errors matched; Retry validation
if [ "$validate_errors_matched" = "1" ]; then
common::colorify "yellow" "Validation failed. Removing cached providers and modules from $dir_path/.terraform"
if [ "$validate_errors_matched" -eq 1 ]; then
common::colorify "yellow" "Validation failed. Removing cached providers and modules from \"$dir_path/.terraform\" directory"
# `.terraform` dir may comprise some extra files, like `environment`
# which stores info about current TF workspace, so we can't just remove
# `.terraform` dir completely.
Expand Down

0 comments on commit b52b475

Please sign in to comment.