cloud_DeleteInstances() now waits for the instances to be terminated

This commit is contained in:
Michael Vines 2019-03-14 21:15:00 -07:00
parent ede99d5913
commit 7498488f5f
No known key found for this signature in database
GPG Key ID: 33F4FDEC4E0E88BD
1 changed files with 22 additions and 1 deletions

View File

@ -59,7 +59,7 @@ __cloud_FindInstances() {
"Name=tag:name,Values=$filter" \
"Name=instance-state-name,Values=pending,running" \
--query "Reservations[].Instances[].[InstanceId,PublicIpAddress,PrivateIpAddress]" \
--output text
--output text \
)
}
@ -223,11 +223,32 @@ cloud_DeleteInstances() {
echo No instances to delete
return
fi
declare names=("${instances[@]/:*/}")
(
set -x
aws ec2 terminate-instances --region "$region" --instance-ids "${names[@]}"
)
# Wait until the instances are terminated
for name in "${names[@]}"; do
while true; do
declare instanceState
instanceState=$(\
aws ec2 describe-instances \
--region "$region" \
--instance-ids "$name" \
--query "Reservations[].Instances[].State.Name" \
--output text \
)
echo "$name: $instanceState"
if [[ $instanceState = terminated ]]; then
break;
fi
sleep 2
done
done
}