Created
August 31, 2018 21:08
-
-
Save jkmart/95e5b068c15a6d7f27385b1e2f5b7555 to your computer and use it in GitHub Desktop.
Terraform module repository validation check
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
command -v terraform >/dev/null 2>&1 || { echo >&2 "Requires terraform bin to be on path; Aborting."; exit 1; } | |
# for each of the provider directories, validate sub-directory modules | |
for Module in ./**/*/; do | |
# Check if *.tf file exists in directory, to handle cases of multiple and empty submodule directories | |
tf_file=$(find ${Module} -maxdepth 1 -type f -name "*.tf" | head -n1) | |
if [ -d "${Module}" ] && [ -a "${tf_file}" ] ; then | |
# Initialize any module plugins for validating | |
terraform init ${Module} >/dev/null | |
# Run validate to make sure syntax is correct | |
if ! terraform validate -check-variables=false ${Module} ; then | |
# exit if validation fails with module path as hint | |
echo "${Module} fails validation" | |
exit 1; | |
fi | |
fi | |
done | |
echo "All modules pass validation" | |
exit 0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment