pre-commit-opentofu/terraform_validate.sh

30 lines
624 B
Bash
Raw Normal View History

#!/usr/bin/env bash
2018-01-24 13:34:34 +01:00
set -e
2018-01-24 13:34:34 +01:00
declare -a paths
index=0
error=0
2018-01-24 13:34:34 +01:00
for file_with_path in "$@"; do
file_with_path="${file_with_path// /__REPLACED__SPACE__}"
2018-01-24 13:34:34 +01:00
paths[index]=$(dirname "$file_with_path")
(("index+=1"))
2018-01-24 13:34:34 +01:00
done
for path_uniq in $(echo "${paths[*]}" | tr ' ' '\n' | sort -u); do
path_uniq="${path_uniq//__REPLACED__SPACE__/ }"
if [[ -n "$(find . -maxdepth 1 -name '*.tf' -print -quit)" ]]; then
if ! terraform validate $path_uniq; then
error=1
echo
echo "Failed path: $path_uniq"
echo "================================"
fi
2018-01-24 13:48:44 +01:00
fi
done
if [[ "${error}" -ne 0 ]]; then
exit 1
fi