-
Notifications
You must be signed in to change notification settings - Fork 576
Expand file tree
/
Copy pathcreate-infrastructure.sh
More file actions
46 lines (34 loc) · 1.46 KB
/
create-infrastructure.sh
File metadata and controls
46 lines (34 loc) · 1.46 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
#!/bin/bash
environment=$1
cluster=${2:-all}
export USE_CURRENT_USER=${USE_CURRENT_USER:-1} # We don't want to change the ARN in exec
echo "Creating infrastructure for environment ${environment} and cluster ${cluster}"
set -Eeuo pipefail
set -u
set -x
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
source $SCRIPT_DIR/lib/common-env.sh
bash $SCRIPT_DIR/update-iam-role.sh $environment
sleep 5
pids=()
cluster_exists=0
aws eks describe-cluster --name "${EKS_CLUSTER_NAME}" &> /dev/null || cluster_exists=$?
if [ $cluster_exists -ne 0 ] && [[ "$cluster" == "standard" || "$cluster" == "all" ]]; then
echo "Creating cluster ${EKS_CLUSTER_NAME}"
bash $SCRIPT_DIR/exec.sh "${environment}" 'cat /cluster/eksctl/cluster.yaml /cluster/eksctl/access-entries.yaml | envsubst | eksctl create cluster -f -' &
pids+=($!)
else
echo "Cluster ${EKS_CLUSTER_NAME} already exists"
fi
auto_cluster_exists=0
aws eks describe-cluster --name "${EKS_CLUSTER_AUTO_NAME}" &> /dev/null || auto_cluster_exists=$?
if [ $auto_cluster_exists -ne 0 ] && [[ "$cluster" == "auto" || "$cluster" == "all" ]]; then
echo "Creating auto mode cluster ${EKS_CLUSTER_AUTO_NAME}"
bash $SCRIPT_DIR/exec.sh "${environment}" 'cat /cluster/eksctl/cluster-auto.yaml /cluster/eksctl/access-entries.yaml | envsubst | eksctl create cluster -f -' &
pids+=($!)
else
echo "Auto mode cluster ${EKS_CLUSTER_AUTO_NAME} already exists"
fi
for pid in "${pids[@]}"; do
wait "$pid" || exit 1
done