-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy-stack.sh
49 lines (40 loc) · 1.64 KB
/
deploy-stack.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
#!/bin/bash
# Parse parameters
while [[ "$#" -gt 0 ]]; do case $1 in
--template-file) TEMPLATE_FILE="$2"; shift;;
--stack-name) STACK_NAME="$2"; shift;;
--profile) PROFILE="$2"; shift;;
--capabilities) CAPABILITY_IAM="$2"; shift;;
--parameter-overrides) PARAMETERS="$2"; shift;;
--role-arn) ROLE_ARN="$2";shift;;
--session) SESSION="$2";shift;;
--region) REGION="$2";shift;;
*) echo "Unknown parameter passed: $1"; exit 1;;
esac; shift; done
# Verify parameters
if [ -z "$TEMPLATE_FILE" ]; then echo "Template file is not set."; exit 1; fi;
if [ -z "$STACK_NAME" ]; then echo "Template file is not set."; exit 1; fi;
if [ -z "$PROFILE" ]; then echo "Profile is not set."; exit 1; fi;
if [ -z "$ROLE_ARN" ]; then echo "Role ARN is not set."; exit 1; fi;
if [ -z "$SESSION" ]; then echo "Role session is not set."; exit 1; fi;
echo Validating stack "$STACK_NAME"
aws cloudformation validate-template \
--template-body "file://$TEMPLATE_FILE" \
--profile "$PROFILE"
ROLE_PROFILE=$STACK_NAME
echo Assuming role
bash "${BASH_SOURCE%/*}/../configure/create-role-profile.sh" \
--role-profile "$ROLE_PROFILE" --user-profile "$PROFILE" \
--role-arn "$ROLE_ARN" \
--session "$SESSION" \
--region "$REGION"
echo Deploying stack "$TEMPLATE_FILE"
[ -n "$CAPABILITY_IAM" ] && echo "Capabilities: $CAPABILITY_IAM"
[ -n "$PARAMETERS" ] && echo "Parameters: $PARAMETERS"
aws cloudformation deploy \
--template-file "$TEMPLATE_FILE" \
--stack-name "$STACK_NAME" \
${CAPABILITY_IAM:+ --capabilities $CAPABILITY_IAM} \
${PARAMETERS:+ --parameter-overrides $PARAMETERS} \
--no-fail-on-empty-changeset \
--profile "$ROLE_PROFILE"