Skip to content

Commit 69039c3

Browse files
robinbowesantonbabenko
authored andcommitted
Only run validate if .tf files exist in the directory. (antonbabenko#20)
* Only run validate if .tf files exist in the directory. * Same fix, different script :)
1 parent 2d3782c commit 69039c3

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

terraform_validate_no_variables.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ for file_with_path in "$@"; do
88
file_with_path="${file_with_path// /__REPLACED__SPACE__}"
99

1010
paths[index]=$(dirname "$file_with_path")
11-
let "index+=1"
11+
(( "index+=1" ))
1212
done
1313

1414
for path_uniq in $(echo "${paths[*]}" | tr ' ' '\n' | sort -u); do
1515
path_uniq="${path_uniq//__REPLACED__SPACE__/ }"
1616

1717
pushd "$path_uniq" > /dev/null
18-
terraform validate -check-variables=false
19-
20-
if [[ "$?" -ne 0 ]]; then
21-
echo
22-
echo "Failed path: $path_uniq"
23-
echo "================================"
18+
if [[ -n "$(find . -maxdepth 1 -name '*.tf' -print -quit)" ]] ; then
19+
if ! terraform validate -check-variables=false ; then
20+
echo
21+
echo "Failed path: $path_uniq"
22+
echo "================================"
23+
fi
2424
fi
2525
popd > /dev/null
2626
done

terraform_validate_with_variables.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ for file_with_path in "$@"; do
88
file_with_path="${file_with_path// /__REPLACED__SPACE__}"
99

1010
paths[index]=$(dirname "$file_with_path")
11-
let "index+=1"
11+
(( "index+=1" ))
1212
done
1313

1414
for path_uniq in $(echo "${paths[*]}" | tr ' ' '\n' | sort -u); do
1515
path_uniq="${path_uniq//__REPLACED__SPACE__/ }"
1616

1717
pushd "$path_uniq" > /dev/null
18-
terraform validate -check-variables=true
19-
20-
if [[ "$?" -ne 0 ]]; then
21-
echo
22-
echo "Failed path: $path_uniq"
23-
echo "================================"
18+
if [[ -n "$(find . -maxdepth 1 -name '*.tf' -print -quit)" ]] ; then
19+
if ! terraform validate -check-variables=true ; then
20+
echo
21+
echo "Failed path: $path_uniq"
22+
echo "================================"
23+
fi
2424
fi
2525
popd > /dev/null
2626
done

0 commit comments

Comments
 (0)