Repository navigation
Expand file tree
/
Copy pathdeploy_aws_environment
More file actions
executable file
·448 lines (377 loc) · 15.2 KB
/
Copy pathdeploy_aws_environment
File metadata and controls
executable file
·448 lines (377 loc) · 15.2 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
#!/bin/bash
set -e
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
function usage() {
>&2 cat <<EOF
SYNOPSIS:
Create a CloudFormation stack, deploy BOSH, and create initial CF and Diego stubs.
USAGE:
$0 <AWS_ACTION> <BOSH_ACTION> <BOSH_DEPLOYMENT_DIR> <DEPLOYMENT_DIR> <STACK_NAME>
MANDATORY ARGUMENTS:
AWS_ACTION: Action to take on AWS CloudFormation stack: create-stack, update-stack, or skip-stack.
BOSH_ACTION: Action to take on BOSH director deployment: deploy-bosh or skip-bosh.
BOSH_DEPLOYMENT_DIR: Path to local copy of the bosh-deployment repository.
DEPLOYMENT_DIR: Directory to store files for this deployment.
STACK_NAME: Name of the CloudFormation stack to create.
EOF
}
indent() {
sed -e 's/^/ /'
}
indent_contents_of() {
indent < "$1"
}
block() {
cat <<-EOF
$1: |
$(indent_contents_of "$2")
EOF
}
oneline() {
cat <<-EOF
$1: '$(cat $2)'
EOF
}
cf_credentials() {
cat <<-EOF
# GENERATED: NO TOUCHING
---
cf_credentials:
ssh_host_key_fingerprint: "$(cat keypair/ssh-proxy-host-key-fingerprint)"
cc:
$(block ca_cert certs/cf-diego-certs/cf-diego-ca.crt | indent | indent)
$(block public_cert certs/cf-diego-certs/cloud-controller.crt | indent | indent)
$(block private_key certs/cf-diego-certs/cloud-controller.key | indent | indent)
consul:
$(block ca_cert certs/consul-certs/server-ca.crt | indent | indent)
$(block agent_cert certs/consul-certs/agent.crt | indent | indent)
$(block agent_key certs/consul-certs/agent.key | indent | indent)
$(block server_cert certs/consul-certs/server.crt | indent | indent)
$(block server_key certs/consul-certs/server.key | indent | indent)
uaa:
$(block signing_key keypair/uaa | indent | indent)
$(block verification_key keypair/uaa.pub | indent | indent)
$(block saml_cert certs/uaa-certs/saml.crt | indent | indent)
$(block saml_key certs/uaa-certs/saml.key | indent | indent)
$(oneline saml_key_password certs/uaa-certs/saml.key.password | indent | indent)
$(block ca_cert certs/uaa-certs/server-ca.crt | indent | indent)
$(block server_key certs/uaa-certs/server.key | indent | indent)
$(block server_cert certs/uaa-certs/server.crt | indent | indent)
loggregator:
$(block ca_cert certs/loggregator-certs/loggregator-ca.crt | indent | indent)
$(block doppler_cert certs/loggregator-certs/doppler.crt | indent | indent)
$(block doppler_key certs/loggregator-certs/doppler.key | indent | indent)
$(block trafficcontroller_cert certs/loggregator-certs/trafficcontroller.crt | indent | indent)
$(block trafficcontroller_key certs/loggregator-certs/trafficcontroller.key | indent | indent)
$(block metron_cert certs/loggregator-certs/metron.crt | indent | indent)
$(block metron_key certs/loggregator-certs/metron.key | indent | indent)
$(block statsd_injector_cert certs/statsd-injector-certs/statsdinjector.crt | indent | indent)
$(block statsd_injector_key certs/statsd-injector-certs/statsdinjector.key | indent | indent)
$(block syslogdrainbinder_cert certs/loggregator-certs/syslogdrainbinder.crt | indent | indent)
$(block syslogdrainbinder_key certs/loggregator-certs/syslogdrainbinder.key | indent | indent)
$(block reverse_log_proxy_cert certs/loggregator-certs/reverselogproxy.crt | indent | indent)
$(block reverse_log_proxy_key certs/loggregator-certs/reverselogproxy.key | indent | indent)
scalablesyslog:
$(block adapter_ca_cert certs/loggregator-certs/loggregator-ca.crt | indent | indent)
$(block adapter_cert certs/loggregator-certs/ss-adapter.crt | indent | indent)
$(block adapter_key certs/loggregator-certs/ss-adapter.key | indent | indent)
$(block adapter_rlp_ca_cert certs/loggregator-certs/loggregator-ca.crt | indent | indent)
$(block adapter_rlp_cert certs/loggregator-certs/ss-adapter-rlp.crt | indent | indent)
$(block adapter_rlp_key certs/loggregator-certs/ss-adapter-rlp.key | indent | indent)
$(block scheduler_client_ca_cert certs/loggregator-certs/loggregator-ca.crt | indent | indent)
$(block scheduler_client_cert certs/loggregator-certs/ss-scheduler.crt | indent | indent)
$(block scheduler_client_key certs/loggregator-certs/ss-scheduler.key | indent | indent)
$(block scheduler_api_ca_cert certs/cf-diego-certs/cf-diego-ca.crt | indent | indent)
$(block scheduler_api_cert certs/loggregator-certs/ss-scheduler-api.crt | indent | indent)
$(block scheduler_api_key certs/loggregator-certs/ss-scheduler-api.key | indent | indent)
EOF
}
diego_credentials() {
cat <<-EOF
# GENERATED: NO TOUCHING
---
diego_credentials:
$(block diego_ca certs/cf-diego-certs/cf-diego-ca.crt | indent)
$(block ssh_proxy_host_key keypair/ssh-proxy-host-key.pem | indent)
bbs:
$(block client_cert certs/bbs-certs/client.crt | indent | indent)
$(block client_key certs/bbs-certs/client.key | indent | indent)
$(block server_cert certs/bbs-certs/server.crt | indent | indent)
$(block server_key certs/bbs-certs/server.key | indent | indent)
locket:
$(block server_cert certs/locket-certs/server.crt | indent | indent)
$(block server_key certs/locket-certs/server.key | indent | indent)
rep:
$(block client_cert certs/rep-certs/client.crt | indent | indent)
$(block client_key certs/rep-certs/client.key | indent | indent)
$(block server_cert certs/rep-certs/server.crt | indent | indent)
$(block server_key certs/rep-certs/server.key | indent | indent)
auctioneer:
$(block client_cert certs/auctioneer-certs/client.crt | indent | indent)
$(block client_key certs/auctioneer-certs/client.key | indent | indent)
$(block server_cert certs/auctioneer-certs/server.crt | indent | indent)
$(block server_key certs/auctioneer-certs/server.key | indent | indent)
tps:
$(block ca_cert certs/cf-diego-certs/cf-diego-ca.crt | indent | indent)
$(block client_cert certs/tps-certs/client.crt | indent | indent)
$(block client_key certs/tps-certs/client.key | indent | indent)
cc_uploader:
$(block ca_cert certs/cf-diego-certs/cf-diego-ca.crt | indent | indent)
$(block server_cert certs/cc-uploader-certs/server.crt | indent | indent)
$(block server_key certs/cc-uploader-certs/server.key | indent | indent)
cc:
$(block ca_cert certs/cf-diego-certs/cf-diego-ca.crt | indent | indent | indent)
$(block client_cert certs/cc-uploader-certs/cc/client.crt | indent | indent | indent)
$(block client_key certs/cc-uploader-certs/cc/client.key | indent | indent | indent)
EOF
}
case "$1" in
"create-stack")
stack_action="create-stack"
;;
"update-stack")
stack_action="update-stack"
;;
"skip-stack")
stack_action=""
;;
*)
usage
exit 1
;;
esac
shift
case "$1" in
"deploy-bosh")
bosh_action="deploy"
;;
"skip-bosh")
bosh_action="skip"
;;
*)
usage
exit 1
;;
esac
shift
bosh_deployment_dir="$1"
shift
deployment_dir="$1"
shift
stack_name="$1"
if [ -z "${stack_name}" ]; then
usage
exit 1
fi
# name of BOSH CLI v2 executable
gobosh="${gobosh:-bosh}"
command -v aws >/dev/null || { echo "aws is required"; exit 1; }
command -v jq >/dev/null || { echo "jq is required"; exit 1; }
command -v spiff >/dev/null || { echo "spiff is required"; exit 1; }
command -v "${gobosh}" >/dev/null || { echo "BOSH CLI v2 is required"; exit 1; }
"${gobosh}" env --help >/dev/null 2>/dev/null || { echo "BOSH CLI v2 is required"; exit 1; }
set -x
pushd ${deployment_dir}
mkdir -p stubs/cf
mkdir -p stubs/infrastructure
mkdir -p deployments/bosh
source bootstrap_environment
# install certs for ELB
if ! aws iam get-server-certificate --server-certificate-name cfrouter; then
aws iam upload-server-certificate \
--server-certificate-name cfrouter \
--private-key file://certs/elb-cfrouter.key \
--certificate-body file://certs/elb-cfrouter.pem
fi
# generate stub to be fed into template for cloudformation
cat > stubs/infrastructure/certificates.yml <<EOF
# GENERATED: NO TOUCHING
EOF
aws iam get-server-certificate --server-certificate-name cfrouter \
>> stubs/infrastructure/certificates.yml
function extra_subnets {
cat <<EOF
---
EOF
if [ -f stubs/infrastructure/extra_subnets.yml ]; then
spiff merge \
stubs/infrastructure/extra_subnets.yml \
$SCRIPT_DIR/templates/infrastructure/meta.yml \
stubs/infrastructure/availability_zones.yml
fi
}
# generate cloudformation template
spiff merge \
$SCRIPT_DIR/templates/infrastructure/boosh.yml \
$SCRIPT_DIR/templates/infrastructure/boosh-internal.yml \
stubs/bosh/vars.yml \
stubs/domain.yml \
stubs/infrastructure/certificates.yml \
$SCRIPT_DIR/templates/infrastructure/meta.yml \
stubs/infrastructure/availability_zones.yml \
<(extra_subnets) \
| boosh generate | jq -c -S . \
> stubs/infrastructure/cloudformation.json
# deploy infrastructure
if [[ -n "$stack_action" ]]; then
aws cloudformation "$stack_action" \
--stack-name $stack_name \
--template-body file://stubs/infrastructure/cloudformation.json
# ensure that create or update was successful to aws
boosh watch --name $stack_name
# generate AWS resources stub for shared purposes
cat > stubs/aws-resources.yml <<EOF
# GENERATED: NO TOUCHING
EOF
boosh resources --name $stack_name >> stubs/aws-resources.yml
fi
cat > "${deployment_dir}/stubs/bosh/aws.yml" <<EOF
# GENERATED: NO TOUCHING
EOF
spiff merge \
"${SCRIPT_DIR}/templates/bosh/aws.yml" \
"${SCRIPT_DIR}/templates/bosh/aws-internal.yml" \
"${deployment_dir}/stubs/aws-resources.yml" \
>> "${deployment_dir}/stubs/bosh/aws.yml"
custom_ops_file_args=$(for i in $(ls ${deployment_dir}/ops-files/bosh/*.yml); do echo -n "--ops-file \"$i\" "; done)
bosh_datadog_args=""
if [[ -f "${deployment_dir}/stubs/bosh/datadog.yml" ]]; then
bosh_datadog_args="
--ops-file \"${SCRIPT_DIR}/ops-files/bosh/datadog.yml\" \
--vars-file \"${deployment_dir}/stubs/bosh/datadog.yml\""
fi
bosh_domain_args=""
if [[ -f "${deployment_dir}/stubs/bosh/domain.yml" ]]; then
bosh_domain_args="
--ops-file \"${SCRIPT_DIR}/ops-files/bosh/domain.yml\" \
--vars-file \"${deployment_dir}/stubs/bosh/domain.yml\""
fi
cat > "${deployment_dir}/deployments/bosh/bosh.yml" <<EOF
# GENERATED: NO TOUCHING
EOF
"${gobosh}" interpolate \
--var-errs \
--var-errs-unused \
"${bosh_deployment_dir}/bosh.yml" \
--vars-store "${deployment_dir}/deployments/bosh/creds.yml" \
--ops-file "${bosh_deployment_dir}/aws/cpi.yml" \
--ops-file "${bosh_deployment_dir}/external-ip-with-registry-not-recommended.yml" \
$custom_ops_file_args \
$bosh_datadog_args \
$bosh_domain_args \
--vars-file "${deployment_dir}/stubs/bosh/aws.yml" \
--vars-file "${deployment_dir}/stubs/bosh/vars.yml" \
--var "private_key=${deployment_dir}/keypair/id_rsa_bosh" \
>> "${deployment_dir}/deployments/bosh/bosh.yml"
if [[ "$bosh_action" == "deploy" ]]; then
"${gobosh}" create-env \
--state "${deployment_dir}/deployments/bosh/state.json" \
--vars-store "${deployment_dir}/deployments/bosh/creds.yml" \
"${deployment_dir}/deployments/bosh/bosh.yml"
elif [[ "$bosh_action" == "skip" ]]; then
>&2 echo "Skipping deployment of BOSH director"
fi
# generate director uuid stub for template to create deployment stub
bosh_ip=$(${gobosh} interpolate "${deployment_dir}/stubs/bosh/aws.yml" --path /external_ip)
director_uuid=$("${gobosh}" \
-e ${bosh_ip} \
--ca-cert "$("${gobosh}" interpolate "${deployment_dir}/deployments/bosh/creds.yml" --path /director_ssl/ca)" \
env --json | jq -r '.Tables[0].Rows[0].uuid')
cat > stubs/director-uuid.yml <<EOF
# GENERATED: NO TOUCHING
---
director_uuid: ${director_uuid}
EOF
# generate stub with deployment base domain
cat > stubs/cf/domain.yml <<EOF
# GENERATED: NO TOUCHING
EOF
spiff merge $SCRIPT_DIR/templates/cf/domain.yml \
$SCRIPT_DIR/templates/cf/domain-internal.yml \
stubs/domain.yml \
>> stubs/cf/domain.yml
# override cf and diego instance types
aws_instance_types=""
if [ -f stubs/aws-instance-types.yml ]; then
aws_instance_types="stubs/aws-instance-types.yml"
fi
# generate deployment stub
cat > stubs/cf/stub.yml <<EOF
# GENERATED: NO TOUCHING
EOF
spiff merge \
$SCRIPT_DIR/templates/cf/stub.yml \
$SCRIPT_DIR/templates/cf/stub-internal.yml \
$aws_instance_types \
stubs/aws-resources.yml \
stubs/cf/domain.yml \
stubs/director-uuid.yml \
<(cf_credentials) \
>> stubs/cf/stub.yml
# copy CF property stub if not already present
if [ ! -f stubs/cf/properties.yml ]; then
cp $SCRIPT_DIR/stubs/cf/properties.yml stubs/cf/properties.yml
fi
mkdir -p stubs/diego
mkdir -p stubs/diego-windows
mkdir -p stubs/routing
# generate Diego property-override stub with certs
if [ -f stubs/diego/property-overrides.yml ]; then
# update BBS certs and keys in existing property-overrides stub
temp_property_overrides=$(mktemp stubs/diego/property-overrides.yml.XXXXX)
spiff merge \
stubs/diego/property-overrides.yml \
$SCRIPT_DIR/templates/diego/property-overrides-internal.yml \
<(diego_credentials) \
> "${temp_property_overrides}"
mv "${temp_property_overrides}" stubs/diego/property-overrides.yml
else
# create new property-overrides stub with default overrides
spiff merge \
$SCRIPT_DIR/templates/diego/property-overrides.yml \
$SCRIPT_DIR/templates/diego/property-overrides-internal.yml \
<(diego_credentials) \
> stubs/diego/property-overrides.yml
fi
# generate Diego IaaS-settings stub
spiff merge \
$SCRIPT_DIR/../../manifest-generation/misc-templates/aws-iaas-settings.yml \
$SCRIPT_DIR/templates/diego/iaas-settings-internal.yml \
$aws_instance_types stubs/aws-resources.yml \
> stubs/diego/iaas-settings.yml
# generate Diego Windows IaaS-settings stub
spiff merge \
$SCRIPT_DIR/../../manifest-generation/misc-templates/windows-iaas-settings.yml \
$SCRIPT_DIR/templates/diego-windows/iaas-settings-internal.yml \
$aws_instance_types stubs/aws-resources.yml \
> stubs/diego-windows/iaas-settings.yml
# generate Routing IaaS-settings stub
spiff merge \
$SCRIPT_DIR/templates/routing/iaas-settings.yml \
stubs/aws-resources.yml \
> stubs/routing/iaas-settings.yml
# generate mysql cloud config stub
spiff merge \
$SCRIPT_DIR/templates/infrastructure/cloud-config.yml \
$SCRIPT_DIR/templates/infrastructure/cloud-config-internal.yml \
$aws_instance_types stubs/aws-resources.yml \
> stubs/cloud-config.yml
mkdir -p stubs/cf-mysql
if [ ! -f stubs/cf-mysql/mysql-overrides-ops.yml ]; then
cp $SCRIPT_DIR/templates/mysql/mysql-overrides-ops.yml stubs/cf-mysql/mysql-overrides-ops.yml
fi
spiff merge $SCRIPT_DIR/templates/mysql/consul-secrets.yml <(cf_credentials) > stubs/cf-mysql/consul-secrets.yml
# generate datadog firehose nozzle manifest if the user stubs exist
if [ -d stubs/datadog-firehose-nozzle ]; then
spiff merge \
$SCRIPT_DIR/templates/datadog-firehose-nozzle/datadog-firehose-nozzle.yml \
stubs/datadog-firehose-nozzle/datadog.yml \
stubs/datadog-firehose-nozzle/property-overrides.yml \
stubs/aws-resources.yml \
stubs/cf/properties.yml \
stubs/cf/stub.yml \
stubs/cf/domain.yml \
stubs/director-uuid.yml \
> deployments/datadog-firehose-nozzle.yml
fi
popd