forked from dbtucker/quickstart-confluent-kafka
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwait-for-child-resource.sh
executable file
·107 lines (94 loc) · 3.28 KB
/
wait-for-child-resource.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
#!/bin/bash
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Specifically, this script is intended SOLELY to support the Confluent
# Quick Start offering in Amazon Web Services. It is not recommended
# for use in any other production environment.
#
#
#
#
# Simple script to wait for a Cloudformation resource identified as
# part of a Cloudformation::Stack chain (using logical resource names).
#
#
# usage:
# $0 ParentStack ChildStack ResourceName
#
# If the ChildStack or the leaf Resource does not exist, this returns immediately.
#
murl_top=http://169.254.169.254/latest/meta-data
ThisInstance=$(curl -f $murl_top/instance-id 2> /dev/null)
if [ -z "$ThisInstance" ] ; then
ThisInstance="unknown"
fi
ThisRegion=$(curl -f $murl_top/placement/availability-zone 2> /dev/null)
if [ -z "$ThisRegion" ] ; then
ThisRegion="us-west-2"
else
ThisRegion="${ThisRegion%[a-z]}"
fi
ParentStack=${1:-}
ChildStack=${2:-}
TargetResource=${3:-}
if [ -z "$ParentStack" -o -z "${ChildStack}" ] ; then
echo "No AWS Cloudformation Stacks specified; aborting script"
exit 1
elif [ -z "$TargetResource" ] ; then
echo "No Resource specified; aborting script"
elif [ -z "$ThisRegion" ] ; then
echo "Failed to determine AWS region; aborthing script"
exit 1
fi
# We need the physical resource id for the ChildStack in order to track the
# leaf Resource, so we're use the following query to retrieve it.
ChildStackId=$(aws cloudformation describe-stack-resources \
--output json \
--region $ThisRegion \
--stack-name $ParentStack \
--query "StackResources[?LogicalResourceId=='${ChildStack}']" \
| jq -r '.[0] | .PhysicalResourceId')
# echo "ChildStackId=$ChildStackId"
if [ -z "${ChildStackId}" -o "${ChildStackId}" = "null" ] ; then
echo "$ChildStack does not exist as a resource in $ParentStack"
exit 0
fi
# Wait for all nodes to come on-line within a group
#
resourceStatus=$(aws cloudformation describe-stack-resources \
--output text \
--region $ThisRegion \
--stack-name $ChildStackId \
--logical-resource-id $TargetResource \
--query StackResources[].ResourceStatus)
if [ -z "$resourceStatus" ] ; then
echo "$TargetResource has does not exist in $ParentStack/$ChildStack"
exit 0
fi
## TBD ... add timeout (optional, since CFT will enforce timeout)
#
while [ $resourceStatus != "CREATE_COMPLETE" ]
do
sleep 30
resourceStatus=$(aws cloudformation describe-stack-resources \
--output text \
--region $ThisRegion \
--stack-name $ChildStackId \
--logical-resource-id $TargetResource \
--query StackResources[].ResourceStatus)
done
echo "$ChildStack/$TargetResource has status $resourceStatus"