Skip to content

Commit 2bca410

Browse files
authored
fix: Support custom TF paths which contains spaces (antonbabenko#714)
1 parent 9d3164c commit 2bca410

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

hooks/_common.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -536,13 +536,13 @@ function common::terraform_init {
536536
# Plugin cache dir can't be written concurrently or read during write
537537
# https://github.com/hashicorp/terraform/issues/31964
538538
if [[ -z $TF_PLUGIN_CACHE_DIR || $parallelism_disabled == true ]]; then
539-
init_output=$($tf_path init -backend=false "${TF_INIT_ARGS[@]}" 2>&1)
539+
init_output=$("$tf_path" init -backend=false "${TF_INIT_ARGS[@]}" 2>&1)
540540
exit_code=$?
541541
else
542542
# Locking just doesn't work, and the below works quicker instead. Details:
543543
# https://github.com/hashicorp/terraform/issues/31964#issuecomment-1939869453
544544
for i in {1..10}; do
545-
init_output=$($tf_path init -backend=false "${TF_INIT_ARGS[@]}" 2>&1)
545+
init_output=$("$tf_path" init -backend=false "${TF_INIT_ARGS[@]}" 2>&1)
546546
exit_code=$?
547547

548548
if [ $exit_code -eq 0 ]; then

hooks/terraform_fmt.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function per_dir_hook_unique_part {
4949
local -a -r args=("$@")
5050

5151
# pass the arguments to hook
52-
$tf_path fmt "${args[@]}"
52+
"$tf_path" fmt "${args[@]}"
5353

5454
# return exit code to common::per_dir_hook
5555
local exit_code=$?

hooks/terraform_providers_lock.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ function per_dir_hook_unique_part {
140140
common::colorify "yellow" "DEPRECATION NOTICE: We introduced '--mode' flag for this hook.
141141
Check migration instructions at https://github.com/antonbabenko/pre-commit-terraform#terraform_providers_lock
142142
"
143-
common::terraform_init 'terraform providers lock' "$dir_path" "$parallelism_disabled" "$tf_path" || {
143+
common::terraform_init "$tf_path providers lock" "$dir_path" "$parallelism_disabled" "$tf_path" || {
144144
exit_code=$?
145145
return $exit_code
146146
}
@@ -155,7 +155,7 @@ Check migration instructions at https://github.com/antonbabenko/pre-commit-terra
155155
#? Don't require `tf init` for providers, but required `tf init` for modules
156156
#? Mitigated by `function match_validate_errors` from terraform_validate hook
157157
# pass the arguments to hook
158-
$tf_path providers lock "${args[@]}"
158+
"$tf_path" providers lock "${args[@]}"
159159

160160
# return exit code to common::per_dir_hook
161161
exit_code=$?

hooks/terraform_validate.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ function per_dir_hook_unique_part {
118118
# First try `terraform validate` with the hope that all deps are
119119
# pre-installed. That is needed for cases when `.terraform/modules`
120120
# or `.terraform/providers` missed AND that is expected.
121-
$tf_path validate "${args[@]}" &> /dev/null && {
121+
"$tf_path" validate "${args[@]}" &> /dev/null && {
122122
exit_code=$?
123123
return $exit_code
124124
}
@@ -132,11 +132,11 @@ function per_dir_hook_unique_part {
132132

133133
if [ "$retry_once_with_cleanup" != "true" ]; then
134134
# terraform validate only
135-
validate_output=$($tf_path validate "${args[@]}" 2>&1)
135+
validate_output=$("$tf_path" validate "${args[@]}" 2>&1)
136136
exit_code=$?
137137
else
138138
# terraform validate, plus capture possible errors
139-
validate_output=$($tf_path validate -json "${args[@]}" 2>&1)
139+
validate_output=$("$tf_path" validate -json "${args[@]}" 2>&1)
140140
exit_code=$?
141141

142142
# Match specific validation errors
@@ -159,7 +159,7 @@ function per_dir_hook_unique_part {
159159
return $exit_code
160160
}
161161

162-
validate_output=$($tf_path validate "${args[@]}" 2>&1)
162+
validate_output=$("$tf_path" validate "${args[@]}" 2>&1)
163163
exit_code=$?
164164
fi
165165
fi

0 commit comments

Comments
 (0)