-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdo_stack.sh
More file actions
executable file
·51 lines (43 loc) · 1.59 KB
/
do_stack.sh
File metadata and controls
executable file
·51 lines (43 loc) · 1.59 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
#!/bin/bash
action=$1
stack=$2
if [[ "$action" =~ ^(create|update)$ ]]; then
echo "You will perform $action for stack $stack"
if [[ "$stack" =~ ^(secure)$ ]]; then
IP_local=`curl -s https://ipinfo.io/ip`
aws ssm put-parameter --name 'SourceCidrIp' --value ${IP_local}'/32' --type String --overwrite
ssh-keygen -t rsa -b 4096 -f udagramKey -C "My Udagram key" -N '' -q
aws ec2 import-key-pair --key-name "udagramKey" --public-key-material fileb://./udagramKey.pub
aws ssm put-parameter --name 'udagramKeyPrivate' --value "$(cat udagramKey)" --type SecureString --overwrite
aws ssm put-parameter --name 'udagramKey' --value "$(cat udagramKey.pub)" --type SecureString --overwrite
echo "Done"
exit
fi
aws cloudformation ${action}-stack \
--stack-name $2 \
--template-body file://stacks/$2.yml \
--parameters file://parameters/$2.json \
--region=eu-west-1 \
--capabilities CAPABILITY_NAMED_IAM
echo "Done"
exit
elif [[ "$action" =~ ^(delete)$ ]]; then
echo "You will perform $action for stack $stack"
if [[ "$stack" =~ ^(secure)$ ]]; then
aws ssm delete-parameter --name 'SourceCidrIp'
aws ec2 delete-key-pair --key-name "udagramKey"
aws ssm delete-parameter --name 'udagramKey'
aws ssm delete-parameter --name 'udagramKeyPrivate'
rm udagramKey*
echo "Done"
exit
fi
aws cloudformation ${action}-stack \
--stack-name $2 \
--region=eu-west-1
echo "Done"
exit
else
echo "Not a valid action"
exit
fi