-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcleanup.sh
executable file
·42 lines (31 loc) · 1.53 KB
/
cleanup.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
#!/bin/bash
: '
The following script cleans up the resources created in
this repository gracefully.
'
declare AWS_REGION="eu-west-1"
cleanup(){
echo "===================================================="
echo "Creating required Environment Variables."
echo "===================================================="
declare ACCOUNT_ID=$(aws sts get-caller-identity --output text --query 'Account')
declare CLUSTER_NAME="eks-cluster-vpc-cni"
declare OIDCURL=$(aws eks describe-cluster --name ${CLUSTER_NAME} --region ${AWS_REGION} --query "cluster.identity.oidc.issuer" --output text | sed -r 's/https:\/\///')
echo "===================================================="
echo "Deleting the OIDC Provider."
echo "===================================================="
aws iam delete-open-id-connect-provider --open-id-connect-provider-arn arn:aws:iam::${ACCOUNT_ID}:oidc-provider/${OIDCURL}
echo "===================================================="
echo "Deleting the IAM Role."
echo "===================================================="
declare CNI_IAM_ROLE="vpc-cni"
declare IAM_POLICY_NAME="AmazonEKS_CNI_Policy"
declare IAM_POLICY_ARN="arn:aws:iam::aws:policy/${IAM_POLICY_NAME}"
aws iam detach-role-policy --role-name ${CNI_IAM_ROLE} --policy-arn ${IAM_POLICY_ARN}
aws iam delete-role --role-name ${CNI_IAM_ROLE}
echo "===================================================="
echo "Deleting the EKS Cluster."
echo "===================================================="
terraform destroy --auto-approve
}
cleanup