Skip to content

Commit

Permalink
tooling: adding a script to validate the examples in the ./examples
Browse files Browse the repository at this point in the history
… folder are valid
  • Loading branch information
tombuildsstuff committed Oct 14, 2021
1 parent 8fda9c9 commit 209917d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ website/node_modules
*.iml
*.test
.terraform.tfstate.lock.info
.terraform.lock.hcl

website/vendor

Expand Down
4 changes: 3 additions & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -134,5 +134,7 @@ teamcity-test:
@$(MAKE) -C .teamcity tools
@$(MAKE) -C .teamcity test

validate-examples:
./scripts/validate-examples.sh

.PHONY: build build-docker test test-docker testacc vet fmt fmtcheck errcheck scaffold-website test-compile website website-test
.PHONY: build build-docker test test-docker testacc vet fmt fmtcheck errcheck scaffold-website test-compile website website-test validate-examples
35 changes: 35 additions & 0 deletions scripts/validate-examples.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash

echo "==> Checking examples validate with 'terraform validate'..."

exampleDirs=$(find ./examples -mindepth 2 -maxdepth 2 -type d '!' -exec test -e "{}/*.tf" ';' -print | sort)
examplesWithErrors=()
hasError=false

for d in $exampleDirs; do
echo "Validating $d.."
exampleHasErrors=false
terraform -chdir=$d init > /dev/null || exampleHasErrors=true
if ! ${exampleHasErrors}; then
terraform -chdir=$d validate > /dev/null || exampleHasErrors=true
fi
if ${exampleHasErrors}; then
examplesWithErrors[${#examplesWithErrors[@]}]=$d
hasError=true
fi
done

if ${hasError}; then
echo "------------------------------------------------"
echo ""
echo "The directories listed below failed to validate using 'terraform validate'"
echo "Please fix the validation errors for these, these can be found by running"
echo "'terraform init' and then 'terraform validate':"
for exampleDir in "${examplesWithErrors[@]}"
do
echo "- $exampleDir"
done
exit 1
fi

exit 0

0 comments on commit 209917d

Please sign in to comment.