Skip to content

Commit beb4a67

Browse files
josiahhalmeantonbabenko
authored andcommitted
Add exit code for 'terraform validate' so pre-commit check fails (antonbabenko#34)
1 parent 66214dc commit beb4a67

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

terraform_validate_with_variables.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ set -e
33

44
declare -a paths
55
index=0
6+
error=0
67

78
for file_with_path in "$@"; do
89
file_with_path="${file_with_path// /__REPLACED__SPACE__}"
@@ -17,10 +18,15 @@ for path_uniq in $(echo "${paths[*]}" | tr ' ' '\n' | sort -u); do
1718
pushd "$path_uniq" > /dev/null
1819
if [[ -n "$(find . -maxdepth 1 -name '*.tf' -print -quit)" ]] ; then
1920
if ! terraform validate -check-variables=true ; then
21+
error=1
2022
echo
2123
echo "Failed path: $path_uniq"
2224
echo "================================"
2325
fi
2426
fi
2527
popd > /dev/null
2628
done
29+
30+
if [[ -n "${error}" ]] ; then
31+
exit 1
32+
fi

0 commit comments

Comments
 (0)