-
Notifications
You must be signed in to change notification settings - Fork 7
/
aws-cloudformation-validate-template
executable file
·71 lines (62 loc) · 1.92 KB
/
aws-cloudformation-validate-template
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env bash
set -euo pipefail
YP_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." >/dev/null && pwd)"
source ${YP_DIR}/sh/common.inc.sh
#- aws-cloudformation-validate-template 1.0
## Usage: aws-cloudformation-validate-template [OPTION]
## Validate a CloudFormation template.
##
## --template-body Translated to --template-url. This works around the lower size limits of template-body vs template-url
## --template-url-prefix Location to upload template body
##
## -h, --help Display this help and exit
## -v, --version Output version information and exit
TEMPLATE_BODY_ARG=
TEMPLATE_BODY=
TEMPLATE_URL_PREFIX=
if { getopt --test >/dev/null 2>&1 && false; } || [[ "$?" = "4" ]] || false; then
ARGS=$(getopt -o hv -l help,version,template-body:,template-url-prefix: -n $(basename ${BASH_SOURCE[0]}) -- "$@") || sh_script_usage # editorconfig-checker-disable-line
eval set -- "${ARGS}"
fi
while [[ $# -gt 0 ]]; do
case "$1" in
--template-body)
TEMPLATE_BODY="$2"
TEMPLATE_BODY_ARG="$1 $2"
shift 2
;;
--template-url-prefix)
TEMPLATE_URL_PREFIX="$2"
TEMPLATE_URL="$2/$(uuidgen)"
TEMPLATE_BODY_ARG="--template-url https://s3.amazonaws.com/${TEMPLATE_URL}"
shift 2
;;
-h|--help)
sh_script_usage
;;
-v|--version)
sh_script_version
;;
--)
shift
break
;;
-*)
sh_script_usage
;;
*)
break
;;
esac
done
[[ $# -eq 0 ]] || sh_script_usage
function on_exit() {
if [[ -n ${TEMPLATE_URL_PREFIX} ]]; then
aws s3 rm s3://${TEMPLATE_URL} || true
fi
}
trap on_exit EXIT
if [[ -n ${TEMPLATE_URL_PREFIX} ]]; then
aws s3 cp ${TEMPLATE_BODY#file://} s3://${TEMPLATE_URL}
fi
aws cloudformation validate-template ${TEMPLATE_BODY_ARG}