-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.sh
executable file
·78 lines (63 loc) · 2.05 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
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
#!/usr/bin/env bash
cd $(dirname $0)
function banner {
printf "\n========================================================================================================\n"
printf "| $1\n"
printf "========================================================================================================\n"
}
# logout on any exit
trap 'banner "Finished..."' EXIT
usage() {
echo "Usage: $0 -n <name> [-p profile] [-r <region>] [-a <account> ] [-c <cidr>]" 1>&2
exit 1
}
while getopts ":p:n:i:r:c:a:" o; do
case "${o}" in
r) REGION=${OPTARG}
;;
n) NAME=${OPTARG}
;;
c) CIDR=${OPTARG}
;;
a) ACCOUNT=${OPTARG}
;;
*) usage
;;
esac
done
shift $((OPTIND-1))
if [ -z "${NAME}" ]
then
usage
fi
banner "Starting"
ROLE="lba_role"
ACCOUNT="${ACCOUNT:=422515236307}"
banner "Assuming admin role"
JSON=$(aws --profile ${PROFILE:=lba_group} sts assume-role --role-arn arn:aws:iam::${ACCOUNT}:role/admin-access --role-session-name $USER --output json)
if [ ! -z "$JSON" ]
then
aws --profile ${ROLE} configure set aws_access_key_id "$(echo $JSON | jq -r .Credentials.AccessKeyId)"
aws --profile ${ROLE} configure set aws_secret_access_key "$(echo $JSON | jq -r .Credentials.SecretAccessKey)"
aws --profile ${ROLE} configure set aws_session_token "$(echo $JSON | jq -r .Credentials.SessionToken)"
aws --profile ${ROLE} sts get-caller-identity
else
echo "ERROR: failed to be able to assume the admin role in the target account ${ACCOUNT}"
exit 1
fi
banner "Fetching test files"
mkdir -p data
cd data
wget https://raw.githubusercontent.com/krlawrence/graph/master/sample-data/air-routes-latest-edges.csv
wget https://raw.githubusercontent.com/krlawrence/graph/master/sample-data/air-routes-latest-nodes.csv
cd ..
banner "Executing terraform"
cat <<EOF |tee terraform.tfvars
aws_region = "${REGION:=eu-west-2}"
aws_profile = "${ROLE}"
aws_account_id = "${ACCOUNT}"
vpc_cidr = "${CIDR:=172.18.0.0/16}"
vpc_name = "${NAME}"
EOF
terraform init -upgrade=true
terraform apply -var-file=terraform.tfvars