-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaws-switch-to.sh
executable file
·48 lines (40 loc) · 1.52 KB
/
aws-switch-to.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
#!/usr/bin/env bash
function aws_switch_to() {
envname=$1
export AWS_PROFILE=$envname
export AWS_ACCOUNT_NAME=$envname
export AWS_DEFAULT_REGION=eu-central-1
arh aws login
echo "Please provide the wished cluster name or type one of the following options:"
echo " - Use 'list' or 'l' to list available clusters and select one"
echo " - Use 'active', 'a' or press enter to connect to the active cluster"
echo " - Use 'none' or 'n' to skip connecting to a cluster (removes current)"
read cluster_name
# needs to be first, to correctly process pressing enter
if [[ "$cluster_name" == "active" || "$cluster_name" == "a" || "$cluster_name" == "" ]]; then
cluster_name=""
for cluster in $(aws eks list-clusters --query clusters --output text); do
if [ $(aws eks describe-cluster --name $cluster --query cluster.tags.active --output text) = true ]; then
cluster_name=$cluster
break
fi
done
fi
if [[ "$cluster_name" == "none" || "$cluster_name" == "n" ]]; then
cluster_name=""
fi
if [[ "$cluster_name" == "list" || "$cluster_name" == "l" ]]; then
echo "Please select a cluster by number"
echo "0) None (skip connecting to a cluster)"
cluster_name=""
select cluster_name in $(aws eks list-clusters --query clusters --output text); do
break
done
fi
if [[ "$cluster_name" != "" ]]; then
aws eks update-kubeconfig --name $cluster_name --region $AWS_DEFAULT_REGION
else;
kubectl config unset current-context
echo "Unset Kubernetes context"
fi
}