From a5781f3beddfba825d6f19cf70912b8c709d4bc4 Mon Sep 17 00:00:00 2001 From: Robin Bowes Date: Thu, 24 May 2018 20:54:57 +0100 Subject: [PATCH 1/2] Only run validate if .tf files exist in the directory. --- terraform_validate_no_variables.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/terraform_validate_no_variables.sh b/terraform_validate_no_variables.sh index 6a43177a7..2e190448a 100755 --- a/terraform_validate_no_variables.sh +++ b/terraform_validate_no_variables.sh @@ -8,19 +8,19 @@ for file_with_path in "$@"; do file_with_path="${file_with_path// /__REPLACED__SPACE__}" paths[index]=$(dirname "$file_with_path") - let "index+=1" + (( "index+=1" )) done for path_uniq in $(echo "${paths[*]}" | tr ' ' '\n' | sort -u); do path_uniq="${path_uniq//__REPLACED__SPACE__/ }" pushd "$path_uniq" > /dev/null - terraform validate -check-variables=false - - if [[ "$?" -ne 0 ]]; then - echo - echo "Failed path: $path_uniq" - echo "================================" + if [[ -n "$(find . -maxdepth 1 -name '*.tf' -print -quit)" ]] ; then + if ! terraform validate -check-variables=false ; then + echo + echo "Failed path: $path_uniq" + echo "================================" + fi fi popd > /dev/null done From f6b26d58b9e9b8b3bf8dd68f1b53269108abf961 Mon Sep 17 00:00:00 2001 From: Robin Bowes Date: Thu, 24 May 2018 21:10:04 +0100 Subject: [PATCH 2/2] Same fix, different script :) --- terraform_validate_with_variables.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/terraform_validate_with_variables.sh b/terraform_validate_with_variables.sh index 42f1b5452..706443ade 100755 --- a/terraform_validate_with_variables.sh +++ b/terraform_validate_with_variables.sh @@ -8,19 +8,19 @@ for file_with_path in "$@"; do file_with_path="${file_with_path// /__REPLACED__SPACE__}" paths[index]=$(dirname "$file_with_path") - let "index+=1" + (( "index+=1" )) done for path_uniq in $(echo "${paths[*]}" | tr ' ' '\n' | sort -u); do path_uniq="${path_uniq//__REPLACED__SPACE__/ }" pushd "$path_uniq" > /dev/null - terraform validate -check-variables=true - - if [[ "$?" -ne 0 ]]; then - echo - echo "Failed path: $path_uniq" - echo "================================" + if [[ -n "$(find . -maxdepth 1 -name '*.tf' -print -quit)" ]] ; then + if ! terraform validate -check-variables=true ; then + echo + echo "Failed path: $path_uniq" + echo "================================" + fi fi popd > /dev/null done