Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Budi Darmawan committed Jun 11, 2021
2 parents da4c952 + 0a0cf4d commit 6b6c48d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
Binary file removed .DS_Store
Binary file not shown.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ openshift_pull_secret.json
.terraform.lock.hcl
*.pem
installer-files/**

# OS X files
.DS_Store
38 changes: 38 additions & 0 deletions delocp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash

clusterId=$1

if [ -z $clusterId ]; then
exit 99
fi

terraform destroy -auto-approve &

sleep 10
workers=$(aws ec2 describe-instances --filters Name="tag:kubernetes.io/cluster/${clusterId}",Values="owned" --query 'Reservations[].Instances[].[InstanceId, Tags[?Key==`Name`] | [0].Value]' --output text | grep worker | cut -d$'\t' -f1)

aws ec2 terminate-instances --instance-ids ${workers}

vpcid=$(grep vpc terraform.tfstate | grep vpc_id | grep vpc- | head -1 | cut -d"\"" -f4)
elbname=$(aws elb describe-load-balancers --query 'LoadBalancerDescriptions[].[LoadBalancerName,VPCId]' --output text | cut -d$'\t' -f1)
aws elb delete-load-balancer --load-balancer-name ${elbname}

sleep 300

sg=$(aws ec2 describe-security-groups --filters Name="tag:kubernetes.io/cluster/${clusterId}",Values="owned" --query 'SecurityGroups[].[GroupId,GroupName]' --output text | grep "k8s-elb" | cut -d$'\t' -f1)

aws ec2 delete-security-group --group-id ${sg}

sleep 60

aws s3 ls | grep ${clusterId} | awk '{print "aws s3 rb —force s3://"$3}' | bash

aws iam list-users --query 'Users[].[UserName,UserId]' --output text | grep ${clusterId}

aws iam list-users --query 'Users[].[UserName,UserId]' --output text | grep ${clusterId} | awk '{print "aws iam delete-user-policy --user-name "$1" --policy-name "$1"-policy"}' | bash

aws iam list-users --query 'Users[].[UserName,UserId]' --output text | grep ${clusterId} | awk '{print "aws iam delete-access-key --user-name "$1" --access-key-id $(aws iam list-access-keys --user-name "$1" --query 'AccessKeyMetadata[].AccessKeyId' --output text)"}' | bash

aws iam list-users --query 'Users[].[UserName,UserId]' --output text | grep ${clusterId} | awk '{print "aws iam delete-user --user-name "$1}' | bash

exit 0

0 comments on commit 6b6c48d

Please sign in to comment.