diff --git a/hooks/terraform_validate.sh b/hooks/terraform_validate.sh index 24e9069e4..e9a708acf 100755 --- a/hooks/terraform_validate.sh +++ b/hooks/terraform_validate.sh @@ -58,6 +58,7 @@ function match_validate_errors { "Could not load plugin") return 1 ;; "Missing required provider") return 1 ;; *"there is no package for"*"cached in .terraform/providers") return 1 ;; + *"Could not retrieve the list of available versions for provider"*) return 1 ;; esac done < <(jq -rc '.diagnostics[]' <<< "$validate_output") @@ -67,9 +68,11 @@ function match_validate_errors { ####################################################################### # Unique part of `common::per_dir_hook`. The function is executed in loop # on each provided dir path. Run wrapped tool with specified arguments -# 1. Check if `.terraform` dir exists and if not - run `terraform init` -# 2. Run `terraform validate` -# 3. If at least 1 check failed - change the exit code to non-zero +# 1. Run `terraform validate` +# 2. If validate fails, run `terraform init` and retry +# 3. If --retry-once-with-cleanup is enabled and plugin cache parallelism +# causes a race condition, the error is caught by match_validate_errors +# and retried with cleanup # Arguments: # dir_path (string) PATH to dir relative to git repo root. # Can be used in error logging @@ -155,7 +158,7 @@ function per_dir_hook_unique_part { common::colorify "yellow" "Re-validating: $dir_path" - common::terraform_init "$tf_path validate" "$dir_path" "$parallelism_disabled" "$tf_path" || { + common::terraform_init "$tf_path validate" "$dir_path" "true" "$tf_path" || { exit_code=$? return $exit_code }