Skip to content

Instantly share code, notes, and snippets.

@pebo
Created March 28, 2017 06:34
Show Gist options
  • Save pebo/8dd7caa53ca35f64fdb91ca9a0755543 to your computer and use it in GitHub Desktop.
Save pebo/8dd7caa53ca35f64fdb91ca9a0755543 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -e
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
PROGRAM=`basename $0`
usage() {
cat <<EOT
Usage: $PROGRAM <ENV_NAME> [up|down|status]
Controls the bastion host in the specified ENV.
EOT
}
err_echo() {
echo "$@" 1>&2
}
err_exit() {
if [ ! -z "$@" ]; then
err_echo
err_echo "$@"
fi
exit 1
}
ENV_NAME=$1
COMMAND=$2
if [ -z $COMMAND ]; then
usage
err_exit "parameter missing."
fi
BastionASG=$(aws cloudformation describe-stacks --stack-name $ENV_NAME-aniko-infra --query 'Stacks[].Outputs[?OutputKey==`BastionASG`].OutputValue' --output text)
echo
if [ $COMMAND == 'status' ]; then
DesiredCapacity=$(aws autoscaling describe-auto-scaling-groups --auto-scaling-group-names=$BastionASG --query 'AutoScalingGroups[].DesiredCapacity' --output text)
echo DesiredCapacity is $DesiredCapacity
exit 0
fi
if [ $COMMAND == 'up' ]; then
aws autoscaling set-desired-capacity --auto-scaling-group-name=$BastionASG --desired-capacity=1
exit 0
fi
if [ $COMMAND == 'down' ]; then
aws autoscaling set-desired-capacity --auto-scaling-group-name=$BastionASG --desired-capacity=0
exit 0
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment