-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathvalidate.sh
executable file
·52 lines (42 loc) · 1.49 KB
/
validate.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/bash
# This is a simple bash script for the BBB Application Infrastructure.
# It simply validates the Amazon Cloudformation templates.
# created by David Surey - [email protected]
# Disclaimber: NOT FOR PRODUCTION USE - Only for demo and testing purposes
ERROR_COUNT=0;
if [[ $# -lt 1 ]] ; then
echo 'arguments missing, please provide a aws profile string (-p)'
exit 1
fi
while getopts ":p:e:s" opt; do
case $opt in
p) BBBPROFILE="$OPTARG"
;;
\?) echo "Invalid option -$OPTARG" >&2
;;
esac
done
echo "using AWS Profile $BBBPROFILE"
echo "##################################################"
echo "Validating AWS CloudFormation templates..."
echo "##################################################"
# Loop through the YAML templates in this repository
for TEMPLATE in $(find . -name 'bbb-on-aws-*.template.yaml'); do
# Validate the template with CloudFormation
ERRORS=$(aws cloudformation validate-template --profile=$BBBPROFILE --template-body file://$TEMPLATE 2>&1 >/dev/null);
if [ "$?" -gt "1" ]; then
((ERROR_COUNT++));
echo "[fail] $TEMPLATE: $ERRORS";
else
echo "[pass] $TEMPLATE";
fi;
done;
# Error out if templates are not validate.
echo "$ERROR_COUNT template validation error(s)";
if [ "$ERROR_COUNT" -gt 1 ];
then exit 1;
fi
echo "##################################################"
echo "Validating of AWS CloudFormation templates finished"
echo "##################################################"
exit 0