cleanup ec2: Ignore terminated instances
If users had previously terminated an instance and recreated it, e.g manually in the console, the clean-up script will have issues since terminated instance remain available in AWS some time. This commit only takes instances with a state of stopped or running for termination.pull/101/head
parent
0450e2b3b7
commit
bffb753b1b
|
@ -67,7 +67,7 @@ KUBERNETES_HOSTS=(controller0 controller1 controller2 worker0 worker1 worker2)
|
||||||
```
|
```
|
||||||
for host in ${KUBERNETES_HOSTS[*]}; do
|
for host in ${KUBERNETES_HOSTS[*]}; do
|
||||||
INSTANCE_ID=$(aws ec2 describe-instances \
|
INSTANCE_ID=$(aws ec2 describe-instances \
|
||||||
--filters "Name=tag:Name,Values=${host}" | \
|
--filters "Name=tag:Name,Values=${host}" "Name=instance-state-name,Values=running,stopped" | \
|
||||||
jq -j '.Reservations[].Instances[].InstanceId')
|
jq -j '.Reservations[].Instances[].InstanceId')
|
||||||
aws ec2 terminate-instances --instance-ids ${INSTANCE_ID}
|
aws ec2 terminate-instances --instance-ids ${INSTANCE_ID}
|
||||||
done
|
done
|
||||||
|
|
Loading…
Reference in New Issue