-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_cf_stack.sh
executable file
·142 lines (135 loc) · 5.29 KB
/
update_cf_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
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/usr/bin/env bash
AWS_ACCOUNT_ID=$(aws sts get-caller-identity --output text --query 'Account')
AWS_INFRA_CF_BUCKET_URL="https://s3.amazonaws.com/bootstrap-awss3cloudformationbucket-19qromfd235z9"
CF_BUCKET_URL="https://s3.amazonaws.com/bootstrap-awss3cloudformationbucket-114n2ojlbvj21"
STACK_NAME="bootstrap"
CF_TEMPLATE="$STACK_NAME.yml"
echo -e "\nUpdating $STACK_NAME with template $AWS_INFRA_CF_BUCKET_URL/aws-infra/master/$CF_TEMPLATE"
UPDATE_CMD="aws cloudformation update-stack \
--stack-name $STACK_NAME \
--capabilities CAPABILITY_NAMED_IAM \
--notification-arns $CloudformationNotifyLambdaTopicArn \
--template-url $AWS_INFRA_CF_BUCKET_URL/aws-infra/master/$CF_TEMPLATE"
# Handle message that shouldn't be an error, https://github.com/hashicorp/terraform/issues/5653
message=$($UPDATE_CMD 2>&1 1>/dev/null)
error_code=$(echo $?)
if [[ $error_code -ne 0 && $message =~ .*"No updates are to be performed".* ]]; then
echo -e "\nNo stack changes detected. An update is not required."
error_code=0
elif [[ $error_code -ne 0 ]]; then
echo $message
exit $error_code
else
echo $message
fi
STACK_NAME="essentials"
CF_TEMPLATE="$STACK_NAME.yml"
echo -e "\nUpdating $STACK_NAME with template $AWS_INFRA_CF_BUCKET_URL/aws-infra/master/$CF_TEMPLATE"
UPDATE_CMD="aws cloudformation update-stack \
--stack-name $STACK_NAME \
--capabilities CAPABILITY_NAMED_IAM \
--notification-arns $CloudformationNotifyLambdaTopicArn \
--template-url $AWS_INFRA_CF_BUCKET_URL/aws-infra/master/$CF_TEMPLATE \
--parameters \
ParameterKey=FhcrcVpnCidrip,ParameterValue=\"$FhcrcVpnCidrip\" \
ParameterKey=OperatorEmail,ParameterValue=\"$OperatorEmail\" \
ParameterKey=VpcPeeringRequesterAwsAccountId,ParameterValue=\"$AdmincentralAwsAccountId\""
message=$($UPDATE_CMD 2>&1 1>/dev/null)
error_code=$(echo $?)
if [[ $error_code -ne 0 && $message =~ .*"No updates are to be performed".* ]]; then
echo -e "\nNo stack changes detected. An update is not required."
error_code=0
elif [[ $error_code -ne 0 ]]; then
echo $message
exit $error_code
else
echo $message
fi
STACK_NAME="accounts"
CF_TEMPLATE="$STACK_NAME.yml"
echo -e "\nUpdating $STACK_NAME with template cf_templates/$CF_TEMPLATE"
UPDATE_CMD="aws cloudformation update-stack \
--stack-name $STACK_NAME \
--capabilities CAPABILITY_NAMED_IAM \
--notification-arns $CloudformationNotifyLambdaTopicArn \
--template-body file://cf_templates/$CF_TEMPLATE \
--parameters \
ParameterKey=InitNewUserPassword,ParameterValue=\"$InitNewUserPassword\""
message=$($UPDATE_CMD 2>&1 1>/dev/null)
error_code=$(echo $?)
if [[ $error_code -ne 0 && $message =~ .*"No updates are to be performed".* ]]; then
echo -e "\nNo stack changes detected. An update is not required."
error_code=0
elif [[ $error_code -ne 0 ]]; then
echo $message
exit $error_code
else
echo $message
fi
STACK_NAME="computevpc"
CF_TEMPLATE="vpc.yml"
echo -e "\nUpdating $STACK_NAME with template $AWS_INFRA_CF_BUCKET_URL/aws-infra/master/$CF_TEMPLATE"
UPDATE_CMD="aws cloudformation update-stack \
--stack-name $STACK_NAME \
--capabilities CAPABILITY_NAMED_IAM \
--notification-arns $CloudformationNotifyLambdaTopicArn \
--template-url $AWS_INFRA_CF_BUCKET_URL/aws-infra/master/$CF_TEMPLATE \
--parameters \
ParameterKey=VpcName,ParameterValue=\"$STACK_NAME\" \
ParameterKey=VpcSubnetPrefix,ParameterValue="10.5""
message=$($UPDATE_CMD 2>&1 1>/dev/null)
error_code=$(echo $?)
if [[ $error_code -ne 0 && $message =~ .*"No updates are to be performed".* ]]; then
echo -e "\nNo stack changes detected. An update is not required."
error_code=0
elif [[ $error_code -ne 0 ]]; then
echo $message
exit $error_code
else
echo $message
fi
STACK_NAME="peer-vpn-computevpc"
CF_TEMPLATE="peer-route-config.yml"
echo -e "\nUpdating $STACK_NAME with template $AWS_INFRA_CF_BUCKET_URL/aws-infra/master/$CF_TEMPLATE"
UPDATE_CMD="aws cloudformation update-stack \
--stack-name $STACK_NAME \
--capabilities CAPABILITY_NAMED_IAM \
--notification-arns $CloudformationNotifyLambdaTopicArn \
--template-url $AWS_INFRA_CF_BUCKET_URL/aws-infra/master/$CF_TEMPLATE \
--parameters \
ParameterKey=PeeringConnectionId,ParameterValue="pcx-e6cd3b8e" \
ParameterKey=VpcPrivateRouteTable,ParameterValue="rtb-5f73c623" \
ParameterKey=VpcPublicRouteTable,ParameterValue="rtb-6e7fca12" \
ParameterKey=VpnCidr,ParameterValue="10.1.0.0/16""
message=$($UPDATE_CMD 2>&1 1>/dev/null)
error_code=$(echo $?)
if [[ $error_code -ne 0 && $message =~ .*"No updates are to be performed".* ]]; then
echo -e "\nNo stack changes detected. An update is not required."
error_code=0
elif [[ $error_code -ne 0 ]]; then
echo $message
exit $error_code
else
echo $message
fi
STACK_NAME="jc-clean-systems"
CF_TEMPLATE="jumpcloud.yml"
echo -e "\nUpdating $STACK_NAME with template cf_templates/$CF_TEMPLATE"
UPDATE_CMD="aws cloudformation update-stack \
--stack-name $STACK_NAME \
--capabilities CAPABILITY_NAMED_IAM \
--notification-arns $CloudformationNotifyLambdaTopicArn \
--template-body file://cf_templates/$CF_TEMPLATE \
--parameters \
ParameterKey=JcServiceApiKey,ParameterValue=\"$JcServiceApiKey\""
message=$($UPDATE_CMD 2>&1 1>/dev/null)
error_code=$(echo $?)
if [[ $error_code -ne 0 && $message =~ .*"No updates are to be performed".* ]]; then
echo -e "\nNo stack changes detected. An update is not required."
error_code=0
elif [[ $error_code -ne 0 ]]; then
echo $message
exit $error_code
else
echo $message
fi