Skip to content
11 changes: 7 additions & 4 deletions hooks/terraform_validate.sh
Comment thread
MaxymVlasov marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ function match_validate_errors {
"Could not load plugin") return 1 ;;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And I found out that it was replaced to different error msg in TF v1.1, so let's update it as well

https://github.com/search?q=repo%3Ahashicorp%2Fterraform+%22Could+not+load+plugin%22&type=pullrequests

Suggested change
"Could not load plugin") return 1 ;;
*"terraform init"*) 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")

Expand All @@ -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
Expand Down Expand Up @@ -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" || {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert this. It works fine in some cases

Suggested change
common::terraform_init "$tf_path validate" "$dir_path" "true" "$tf_path" || {
common::terraform_init "$tf_path validate" "$dir_path" "$parallelism_disabled" "$tf_path" || {

exit_code=$?
return $exit_code
}
Expand Down