Skip to content

Commit

Permalink
fix: Support custom TF paths which contains spaces (#714)
Browse files Browse the repository at this point in the history
  • Loading branch information
robinbowes authored Sep 9, 2024
1 parent 9d3164c commit 2bca410
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions hooks/_common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -536,13 +536,13 @@ function common::terraform_init {
# Plugin cache dir can't be written concurrently or read during write
# https://github.com/hashicorp/terraform/issues/31964
if [[ -z $TF_PLUGIN_CACHE_DIR || $parallelism_disabled == true ]]; then
init_output=$($tf_path init -backend=false "${TF_INIT_ARGS[@]}" 2>&1)
init_output=$("$tf_path" init -backend=false "${TF_INIT_ARGS[@]}" 2>&1)
exit_code=$?
else
# Locking just doesn't work, and the below works quicker instead. Details:
# https://github.com/hashicorp/terraform/issues/31964#issuecomment-1939869453
for i in {1..10}; do
init_output=$($tf_path init -backend=false "${TF_INIT_ARGS[@]}" 2>&1)
init_output=$("$tf_path" init -backend=false "${TF_INIT_ARGS[@]}" 2>&1)
exit_code=$?

if [ $exit_code -eq 0 ]; then
Expand Down
2 changes: 1 addition & 1 deletion hooks/terraform_fmt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function per_dir_hook_unique_part {
local -a -r args=("$@")

# pass the arguments to hook
$tf_path fmt "${args[@]}"
"$tf_path" fmt "${args[@]}"

# return exit code to common::per_dir_hook
local exit_code=$?
Expand Down
4 changes: 2 additions & 2 deletions hooks/terraform_providers_lock.sh
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ function per_dir_hook_unique_part {
common::colorify "yellow" "DEPRECATION NOTICE: We introduced '--mode' flag for this hook.
Check migration instructions at https://github.com/antonbabenko/pre-commit-terraform#terraform_providers_lock
"
common::terraform_init 'terraform providers lock' "$dir_path" "$parallelism_disabled" "$tf_path" || {
common::terraform_init "$tf_path providers lock" "$dir_path" "$parallelism_disabled" "$tf_path" || {
exit_code=$?
return $exit_code
}
Expand All @@ -155,7 +155,7 @@ Check migration instructions at https://github.com/antonbabenko/pre-commit-terra
#? Don't require `tf init` for providers, but required `tf init` for modules
#? Mitigated by `function match_validate_errors` from terraform_validate hook
# pass the arguments to hook
$tf_path providers lock "${args[@]}"
"$tf_path" providers lock "${args[@]}"

# return exit code to common::per_dir_hook
exit_code=$?
Expand Down
8 changes: 4 additions & 4 deletions hooks/terraform_validate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ function per_dir_hook_unique_part {
# First try `terraform validate` with the hope that all deps are
# pre-installed. That is needed for cases when `.terraform/modules`
# or `.terraform/providers` missed AND that is expected.
$tf_path validate "${args[@]}" &> /dev/null && {
"$tf_path" validate "${args[@]}" &> /dev/null && {
exit_code=$?
return $exit_code
}
Expand All @@ -132,11 +132,11 @@ function per_dir_hook_unique_part {

if [ "$retry_once_with_cleanup" != "true" ]; then
# terraform validate only
validate_output=$($tf_path validate "${args[@]}" 2>&1)
validate_output=$("$tf_path" validate "${args[@]}" 2>&1)
exit_code=$?
else
# terraform validate, plus capture possible errors
validate_output=$($tf_path validate -json "${args[@]}" 2>&1)
validate_output=$("$tf_path" validate -json "${args[@]}" 2>&1)
exit_code=$?

# Match specific validation errors
Expand All @@ -159,7 +159,7 @@ function per_dir_hook_unique_part {
return $exit_code
}

validate_output=$($tf_path validate "${args[@]}" 2>&1)
validate_output=$("$tf_path" validate "${args[@]}" 2>&1)
exit_code=$?
fi
fi
Expand Down

0 comments on commit 2bca410

Please sign in to comment.