diff --git a/bin/compute/ec2/delete_test_instances.sh b/bin/compute/ec2/delete_test_instances.sh index c77d36d0..c14431b4 100755 --- a/bin/compute/ec2/delete_test_instances.sh +++ b/bin/compute/ec2/delete_test_instances.sh @@ -14,6 +14,7 @@ if [[ ${INSTANCES_COUNT} -gt 0 ]] ; then echo "Terminating ${INSTANCES_COUNT} test instances..." aws ec2 terminate-instances --instance-ids "$INSTANCES" + echo "Now instances are terminated and will be deleted after few hours" else echo "No instances contains tag \"${TEST_TAG}\" to delete" diff --git a/bin/compute/ec2/list_test_instances.sh b/bin/compute/ec2/list_test_instances.sh index 1ff1c035..6a7a1931 100755 --- a/bin/compute/ec2/list_test_instances.sh +++ b/bin/compute/ec2/list_test_instances.sh @@ -5,11 +5,24 @@ # # List test Amazon EC2 instances # +# Environment variables +# +# BUBBLE_ENV : env file to load. Default is ~/.bubble-test.env or /home/bubble/current/bubble-test.env (whichever is found first) +# AWS_ACCESS_KEY_ID : AWS access key ID +# AWS_SECRET_KEY : AWS secret access key SCRIPT="${0}" SCRIPT_DIR=$(cd $(dirname ${SCRIPT}) && pwd) -BUBBLE_ENV="${HOME}/.bubble-test.env" +if [[ -z "${BUBBLE_ENV}" ]] ; then + if [[ -f "${HOME}/.bubble-test.env" ]] ; then + BUBBLE_ENV="${HOME}/.bubble-test.env" + elif [[ -f "/home/bubble/current/.bubble-test.env" ]] ; then + BUBBLE_ENV="/home/bubble/current/.bubble-test.env" + else + die "bubble environment file not found" + fi +fi if [[ -z "${TEST_TAG}" ]] ; then TEST_TAG="$(cat ${BUBBLE_ENV} | egrep -v '\s*#' | grep TEST_TAG_CLOUD | awk -F '=' '{print $NF}' | tr -d "'" | tr -d '"')" @@ -20,12 +33,12 @@ fi INSTANCES=$(aws ec2 describe-instances --filters "Name=tag:test_instance,Values=${TEST_TAG}" --query "Reservations[].Instances[].InstanceId") -echo "$INSTANCES" -INSTANCES_COUNT="${#INSTANCES[@]}" +((INSTANCES_COUNT=$(echo "${INSTANCES}" | wc -l) - 2)) if [[ ${INSTANCES_COUNT} -gt 0 ]] ; then echo "Found ${INSTANCES_COUNT} test instances contain tag ${TEST_TAG}" + echo "$INSTANCES" else echo "No instances contain tag \"${TEST_TAG}\" found"