Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Support custom TF paths which contains spaces #714

Merged
merged 2 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading