From 784fe4966edaa16c86f5110a995403ac43c687d8 Mon Sep 17 00:00:00 2001 From: Tom Last Date: Thu, 7 Apr 2022 14:54:28 +0100 Subject: [PATCH 1/4] Fix attempt for tflint issue --- hooks/_common.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/hooks/_common.sh b/hooks/_common.sh index 3ff717dd0..7202b9f1a 100644 --- a/hooks/_common.sh +++ b/hooks/_common.sh @@ -138,7 +138,7 @@ function common::per_dir_hook { # run hook for each path for dir_path in $(echo "${dir_paths[*]}" | tr ' ' '\n' | sort -u); do dir_path="${dir_path//__REPLACED__SPACE__/ }" - pushd "$dir_path" > /dev/null || continue + [ -f "$dir_path" ] || continue per_dir_hook_unique_part "$args" "$dir_path" @@ -147,7 +147,6 @@ function common::per_dir_hook { final_exit_code=$exit_code fi - popd > /dev/null done # restore errexit if it was set before the "for" loop From b35425d23a2289f72be15748b51e9c65a10265f6 Mon Sep 17 00:00:00 2001 From: Tom Last Date: Thu, 7 Apr 2022 15:46:57 +0100 Subject: [PATCH 2/4] Review comment --- hooks/_common.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hooks/_common.sh b/hooks/_common.sh index 7202b9f1a..357172247 100644 --- a/hooks/_common.sh +++ b/hooks/_common.sh @@ -138,7 +138,7 @@ function common::per_dir_hook { # run hook for each path for dir_path in $(echo "${dir_paths[*]}" | tr ' ' '\n' | sort -u); do dir_path="${dir_path//__REPLACED__SPACE__/ }" - [ -f "$dir_path" ] || continue + [ ! -d "$dir_path" ] && continue per_dir_hook_unique_part "$args" "$dir_path" From 89bca817dfde625c6603e4b1ffe936430980f2ea Mon Sep 17 00:00:00 2001 From: Tom Last Date: Fri, 8 Apr 2022 08:40:06 +0100 Subject: [PATCH 3/4] Add in the dir_paths to the calls --- hooks/terraform_fmt.sh | 2 +- hooks/terraform_providers_lock.sh | 2 +- hooks/terraform_tflint.sh | 4 ++-- hooks/terraform_tfsec.sh | 2 +- hooks/terragrunt_fmt.sh | 2 +- hooks/terragrunt_validate.sh | 2 +- hooks/terrascan.sh | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/hooks/terraform_fmt.sh b/hooks/terraform_fmt.sh index 62e70810e..59cb73678 100755 --- a/hooks/terraform_fmt.sh +++ b/hooks/terraform_fmt.sh @@ -105,7 +105,7 @@ function per_dir_hook_unique_part { # pass the arguments to hook # shellcheck disable=SC2068 # hook fails when quoting is used ("$arg[@]") - terraform fmt ${args[@]} + terraform fmt ${args[@]} "$dir_path" # return exit code to common::per_dir_hook local exit_code=$? diff --git a/hooks/terraform_providers_lock.sh b/hooks/terraform_providers_lock.sh index 011ee45eb..181181cef 100755 --- a/hooks/terraform_providers_lock.sh +++ b/hooks/terraform_providers_lock.sh @@ -44,7 +44,7 @@ function per_dir_hook_unique_part { # pass the arguments to hook # shellcheck disable=SC2068 # hook fails when quoting is used ("$arg[@]") - terraform providers lock ${args[@]} + terraform providers lock ${args[@]} "$dir_path" # return exit code to common::per_dir_hook local exit_code=$? diff --git a/hooks/terraform_tflint.sh b/hooks/terraform_tflint.sh index f89ab58bf..ea8601bc0 100755 --- a/hooks/terraform_tflint.sh +++ b/hooks/terraform_tflint.sh @@ -36,11 +36,11 @@ function per_dir_hook_unique_part { # Print checked PATH **only** if TFLint have any messages # shellcheck disable=SC2091,SC2068 # Suppress error output - $(tflint ${args[@]} 2>&1) 2> /dev/null || { + $(tflint ${args[@]} "$dir_path" 2>&1) 2> /dev/null || { common::colorify "yellow" "TFLint in $dir_path/:" # shellcheck disable=SC2068 # hook fails when quoting is used ("$arg[@]") - tflint ${args[@]} + tflint ${args[@]} "$dir_path" } # return exit code to common::per_dir_hook diff --git a/hooks/terraform_tfsec.sh b/hooks/terraform_tfsec.sh index b9273827a..fc5c3ca25 100755 --- a/hooks/terraform_tfsec.sh +++ b/hooks/terraform_tfsec.sh @@ -36,7 +36,7 @@ function per_dir_hook_unique_part { # pass the arguments to hook # shellcheck disable=SC2068 # hook fails when quoting is used ("$arg[@]") - tfsec ${args[@]} + tfsec ${args[@]} "$dir_path" # return exit code to common::per_dir_hook local exit_code=$? diff --git a/hooks/terragrunt_fmt.sh b/hooks/terragrunt_fmt.sh index b2a5b0684..1aab6b5c6 100755 --- a/hooks/terragrunt_fmt.sh +++ b/hooks/terragrunt_fmt.sh @@ -33,7 +33,7 @@ function per_dir_hook_unique_part { # pass the arguments to hook # shellcheck disable=SC2068 # hook fails when quoting is used ("$arg[@]") - terragrunt hclfmt ${args[@]} + terragrunt hclfmt ${args[@]} "$dir_path" # return exit code to common::per_dir_hook local exit_code=$? diff --git a/hooks/terragrunt_validate.sh b/hooks/terragrunt_validate.sh index 589b823c8..72f4ff3ca 100755 --- a/hooks/terragrunt_validate.sh +++ b/hooks/terragrunt_validate.sh @@ -33,7 +33,7 @@ function per_dir_hook_unique_part { # pass the arguments to hook # shellcheck disable=SC2068 # hook fails when quoting is used ("$arg[@]") - terragrunt validate ${args[@]} + terragrunt validate ${args[@]} "$dir_path" # return exit code to common::per_dir_hook local exit_code=$? diff --git a/hooks/terrascan.sh b/hooks/terrascan.sh index 5c6415456..3945d335f 100755 --- a/hooks/terrascan.sh +++ b/hooks/terrascan.sh @@ -33,7 +33,7 @@ function per_dir_hook_unique_part { # pass the arguments to hook # shellcheck disable=SC2068 # hook fails when quoting is used ("$arg[@]") - terrascan scan -i terraform ${args[@]} + terrascan scan -i terraform ${args[@]} "$dir_path" # return exit code to common::per_dir_hook local exit_code=$? From afde258978090e4d2382fd90bb230347d0b349ac Mon Sep 17 00:00:00 2001 From: MaxymVlasov Date: Wed, 13 Apr 2022 22:35:10 +0300 Subject: [PATCH 4/4] Fix terraform_fmt --- hooks/terraform_fmt.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/hooks/terraform_fmt.sh b/hooks/terraform_fmt.sh index 59cb73678..9d87c149c 100755 --- a/hooks/terraform_fmt.sh +++ b/hooks/terraform_fmt.sh @@ -58,7 +58,7 @@ function terraform_fmt_ { # run hook for each path for dir_path in $(echo "${dir_paths[*]}" | tr ' ' '\n' | sort -u); do dir_path="${dir_path//__REPLACED__SPACE__/ }" - pushd "$dir_path" > /dev/null || continue + [ ! -d "$dir_path" ] && continue per_dir_hook_unique_part "$args" "$dir_path" @@ -67,7 +67,6 @@ function terraform_fmt_ { final_exit_code=$exit_code fi - popd > /dev/null done # TODO: Unique part