-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreate-stack.sh
executable file
·74 lines (62 loc) · 2 KB
/
create-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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/sh
#
# Simple shell script to run a CloudFormation template with a set of parameters and tags
#
# Example ./create-stack.sh w2c-non-prod base-landscape buaws-webrouter-base-test
# Note: ./create-stack.sh -d will show aws command
Usage () {
cat <<EOF
$0 profile region directory name [other arguments]
This will create a cloudformation stack named "name" which uses the main.yaml CloudFormation template in
the directory "directory" unless a "name.yaml" exists in that directory. In addition it will look in the
"directory/settings" subdirectory for parameters and tags of the form:
directory/settings/name-parameters.json
directory/settings/name-tags.json
EOF
exit
}
debug=
if [ "x$1" = "x-d" ]; then
debug=echo
shift
fi
if [ "$#" -lt 3 ]; then
Usage
fi
profile="$1"
shift
region="$1"
shift
directory="$1"
shift
name="$1"
shift
ARGS="$@"
# figure out the stack to run
if [ -f "${directory}/${name}.yaml" ]; then
ARGS="$ARGS --template-body file://${directory}/${name}.yaml "
elif [ -f "${directory}/main.yaml" ]; then
ARGS="$ARGS --template-body file://${directory}/main.yaml "
else
echo "No main template found in that directory"
Usage
fi
# figure out the parameter file to use
if [ -f"${directory}/settings/${name}-parameters.json" ]; then
ARGS="$ARGS --parameters file://${directory}/settings/${name}-parameters.json "
elif [ -f "${directory}/settings/main-parameters.json" ]; then
ARGS="$ARGS --parameters file://${directory}/settings/main-parameters.json "
else
echo "No parameters were found in the settings subdirectory"
Usage
fi
# figure out the tags file to use
if [ -f "${directory}/settings/${name}-tags.json" ]; then
ARGS="$ARGS --tags file://${directory}/settings/${name}-tags.json "
elif [ -f "${directory}/settings/main-parameters.json" ]; then
ARGS="$ARGS --tags file://${directory}/settings/main-tags.json "
else
echo "# Skipping tags since none were found"
fi
$debug exec aws --profile "$profile" --region "$region" cloudformation create-stack --stack-name "$name" $ARGS
exit