forked from weavenet/aws-ec2-vpn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
52 lines (42 loc) · 1.31 KB
/
setup.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
#!/bin/bash
region=us-west-2
stack_name=aws-ec2-vpn
vpn_pre_shared_key=$1
vpn_username=$2
vpn_password=$3
if [[ -z "${vpn_pre_shared_key// }" ]] ||
[[ -z "${vpn_username// }" ]] ||
[[ -z "${vpn_username// }" ]]; then
echo "Usage: $0 VPN_PRE_SHARED_KEY VPN_USERNAME VPN_PASSWORD"
exit 1
fi
which aws > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "aws cli must be installed and in path."
exit 1
fi
set -e
az=`aws ec2 describe-availability-zones \
--query 'AvailabilityZones[0].ZoneName' \
--output text \
--region $region`
result=`aws cloudformation create-stack \
--region $region \
--stack-name $stack_name \
--template-body file://aws-ec2-vpn.json \
--capabilities CAPABILITY_IAM \
--parameters \
ParameterKey=AvailabilityZone,ParameterValue=$az \
ParameterKey=VpnPreSharedKey,ParameterValue=$vpn_pre_shared_key \
ParameterKey=VpnUserName,ParameterValue=$vpn_username \
ParameterKey=VpnPassword,ParameterValue=$vpn_password`
echo "VPN Setup in progress."
aws cloudformation wait stack-create-complete \
--region $region \
--stack-name $stack_name
ip=`aws cloudformation describe-stacks \
--stack-name $stack_name \
--query 'Stacks[0].Outputs[0].OutputValue' \
--output text \
--region $region`
echo "VPN Setup complete. IP address is '$ip'."