This repository was archived by the owner on Dec 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetStackContext.sh
More file actions
executable file
·127 lines (110 loc) · 3.93 KB
/
setStackContext.sh
File metadata and controls
executable file
·127 lines (110 loc) · 3.93 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/bin/bash
# Set up the necessary environment for Cloud Formation stack management
#
# This script is designed to be sourced into other scripts
if [[ -n "${GENERATION_DEBUG}" ]]; then set ${GENERATION_DEBUG}; fi
# Ensure mandatory arguments have been provided
if [[ (-z "${TYPE}") || \
((-z "${SLICE}") && (! ("${TYPE}" =~ product ))) ]]; then
echo -e "\nInsufficient arguments"
usage
fi
# Set up the context
. ${GENERATION_DIR}/setContext.sh
case $TYPE in
account|product)
if [[ ! ("${TYPE}" =~ ${LOCATION} ) ]]; then
echo -e "\nCurrent directory doesn't match requested type \"${TYPE}\". Are we in the right place?"
usage
fi
;;
solution|segment|application)
if [[ ! ("segment" =~ ${LOCATION} ) ]]; then
echo -e "\nCurrent directory doesn't match requested type \"${TYPE}\". Are we in the right place?"
usage
fi
;;
esac
# Determine the details of the template to be created
PRODUCT_PREFIX="${PRODUCT}"
TYPE_PREFIX="${TYPE}-"
SLICE_PREFIX="${SLICE}-"
REGION_PREFIX="${REGION}-"
SEGMENT_SUFFIX="-${SEGMENT}"
TYPE_SUFFIX="-${TYPE}"
SLICE_SUFFIX="-${SLICE}"
case $TYPE in
account)
CF_DIR="${INFRASTRUCTURE_DIR}/${ACCOUNT}/aws/cf"
PRODUCT_PREFIX="${ACCOUNT}"
REGION_PREFIX="${ACCOUNT_REGION}-"
SEGMENT_SUFFIX=""
# LEGACY: Support stacks created before slices added to account
if [[ "${SLICE}" =~ s3 ]]; then
if [[ -f "${CF_DIR}/${TYPE_PREFIX}${REGION_PREFIX}template.json" ]]; then
SLICE_PREFIX=""
SLICE_SUFFIX=""
fi
fi
;;
product)
CF_DIR="${INFRASTRUCTURE_DIR}/${PRODUCT}/aws/cf"
SEGMENT_SUFFIX=""
# LEGACY: Support stacks created before slices added to product
if [[ "${SLICE}" =~ cmk ]]; then
if [[ -f "${CF_DIR}/${TYPE_PREFIX}${REGION_PREFIX}template.json" ]]; then
SLICE_PREFIX=""
SLICE_SUFFIX=""
fi
fi
;;
solution)
CF_DIR="${INFRASTRUCTURE_DIR}/${PRODUCT}/aws/${SEGMENT}/cf"
TYPE_PREFIX="soln-"
TYPE_SUFFIX="-soln"
;;
segment)
CF_DIR="${INFRASTRUCTURE_DIR}/${PRODUCT}/aws/${SEGMENT}/cf"
TYPE_PREFIX="seg-"
TYPE_SUFFIX="-seg"
# LEGACY: Support old formats for existing stacks so they can be updated
if [[ !("${SLICE}" =~ cmk|cert|dns ) ]]; then
if [[ -f "${CF_DIR}/cont-${SLICE_PREFIX}${REGION_PREFIX}template.json" ]]; then
TYPE_PREFIX="cont-"
TYPE_SUFFIX="-cont"
fi
if [[ -f "${CF_DIR}/container-${REGION}-template.json" ]]; then
TYPE_PREFIX="container-"
TYPE_SUFFIX="-container"
SLICE_PREFIX=""
SLICE_SUFFIX=""
fi
if [[ -f "${CF_DIR}/${SEGMENT}-container-template.json" ]]; then
TYPE_PREFIX="${SEGMENT}-container-"
TYPE_SUFFIX="-container"
SLICE_PREFIX=""
SLICE_SUFFIX=""
REGION_PREFIX=""
fi
fi
# "cmk" now used instead of "key"
if [[ "${SLICE}" == "cmk" ]]; then
if [[ -f "${CF_DIR}/${TYPE_PREFIX}key-${REGION_PREFIX}template.json" ]]; then
SLICE_PREFIX="key-"
SLICE_SUFFIX="-key"
fi
fi
;;
application)
CF_DIR="${INFRASTRUCTURE_DIR}/${PRODUCT}/aws/${SEGMENT}/cf"
TYPE_PREFIX="app-"
TYPE_SUFFIX="-app"
;;
*)
echo -e "\n\"$TYPE\" is not one of the known stack types (account, product, segment, solution, application). Nothing to do."
usage
;;
esac
STACKNAME="${PRODUCT_PREFIX}${SEGMENT_SUFFIX}${TYPE_SUFFIX}${SLICE_SUFFIX}"
TEMPLATE="${TYPE_PREFIX}${SLICE_PREFIX}${REGION_PREFIX}template.json"
STACK="${TYPE_PREFIX}${SLICE_PREFIX}${REGION_PREFIX}stack.json"