-
Notifications
You must be signed in to change notification settings - Fork 0
/
vpcupdate.sh
84 lines (84 loc) · 4.08 KB
/
vpcupdate.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
#!/bin/bash
#source ~/.bash_profile
/usr/local/bin/aws cloudformation describe-stacks --stack-name test-vpc-creation --region us-east-2
status=`echo $?`
echo $status
if [ $status -eq 0 ]
then
/usr/local/bin/aws cloudformation update-stack --stack-name test-vpc-creation --template-body file:///opt/jenkins/subbranch/test/vpc\ template.json.txt --parameters file:///opt/jenkins/subbranch/test/parameters.json --region us-east-2 --capabilities "CAPABILITY_IAM" "CAPABILITY_NAMED_IAM"
while true
do
/usr/local/bin/aws cloudformation describe-stack-events --stack-name test-vpc-creation --region us-east-2 | grep -iE 'ResourceStatus|ResourceType' |sed 's|[",:]||g' | grep -E 'ResourceStatus.*UPDATE_COMPLETE*' > update
/usr/local/bin/aws cloudformation describe-stack-events --stack-name test-vpc-creation --region us-east-2 | grep -iE 'ResourceStatus|ResourceType' |sed 's|[",:]||g' | grep -E 'ResourceStatus.*UPDATE_IN_PROGRESS' > updatestart
cat updatestart
noupdate=`cat updatestart | wc -l`
cat update
nooflines=`cat update | wc -l`
echo "The Loop will continue until stack is completed/updated."
if [ "$nooflines" -gt 0 ] && [ "$nooflines" -lt 2 ];
then
echo "Stack Creation is in Progress,Below are the events happening now"
/usr/local/bin/aws cloudformation describe-stack-events --stack-name test-vpc-creation --region us-east-2 | grep -iE 'ResourceStatus|ResourceType|LogicalResourceId|PhysicalResourceId'
sleep 3s
else
if [ "$nooflines" -ge 2 ] ;
then
echo "Stack Creation Completed"
break
else
if [ "$noupdate" -eq 0 ] ;
then
echo "(ValidationError) when calling the UpdateStack operation: No updates are to be performed."
break
fi
fi
fi
done
while true
do
/usr/local/bin/aws cloudformation describe-stack-resources --stack-name test-vpc-creation --region us-east-2 | grep -iE 'ResourceStatus|ResourceType' |sed 's|[",:]||g' |grep -E 'ResourceStatus.*_COMPLETE|ResourceType.*'
rsatus=`echo $?`
echo $rstatus
if [ $rstatus -ne 0 ];
then
echo "Resources are Created Successfully, below are the details"
/usr/local/bin/aws cloudformation describe-stack-resources --stack-name test-vpc-creation --region us-east-2 | grep -iE 'ResourceStatus|ResourceType|LogicalResourceId'
else
break
fi
done
else
/usr/local/bin/aws cloudformation create-stack --stack-name test-vpc-creation --template-body file:///opt/jenkins/subbranch/test/vpc\ template.json.txt --parameters file:///opt/jenkins/subbranch/test/parameters.json --region us-east-2 --capabilities "CAPABILITY_IAM" "CAPABILITY_NAMED_IAM"
while true
do
/usr/local/bin/aws cloudformation describe-stack-events --stack-name test-vpc-creation --region us-east-2 | grep -iE 'ResourceStatus|ResourceType' |sed 's|[",:]||g' | grep -E 'ResourceType.*AWSCloudFormationStack' > lines
cat lines
nooflines=`cat lines | wc -l`
echo "The Loop will continue until stack is completed/updated."
if [ "$nooflines" -gt 0 ] && [ "$nooflines" -lt 2 ]
then
echo "Stack Creation is in Progress,Below are the events happening now"
/usr/local/bin/aws cloudformation describe-stack-events --stack-name test-vpc-creation --region us-east-2 | grep -iE 'ResourceStatus|ResourceType|LogicalResourceId|PhysicalResourceId'
sleep 3s
else
if [ "$nooflines" -ge 2 ];
then
echo "Stack Creation Completed"
break
fi
fi
done
while true
do
/usr/local/bin/aws cloudformation describe-stack-resources --stack-name test-vpc-creation --region us-east-2 | grep -iE 'ResourceStatus|ResourceType' |sed 's|[",:]||g' |grep -E 'ResourceStatus.*_COMPLETE|ResourceType.*'
rsatus=`echo $?`
echo $rstatus
if [ $rstatus -ne 0 ];
then
echo "Resources are Created Successfully, below are the details"
/usr/local/bin/aws cloudformation describe-stack-resources --stack-name test-vpc-creation --region us-east-2 | grep -iE 'ResourceStatus|ResourceType|LogicalResourceId'
else
break
fi
done
fi