Forked from marknca/remove-opsworks-security-groups.sh
Last active
August 29, 2015 14:13
-
-
Save danlherman/bfc3f717abd02a284efb to your computer and use it in GitHub Desktop.
Added Ruby Flow Server and Java App Server to group removal list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env bash | |
# Remove OpsWorks security groups from the given region | |
# Available regions: | |
# ==================== | |
# ap-northeast-1 => Asia Pacific (Tokyo) Region | |
# ap-southeast-1 => Asia Pacific (Singapore) Region | |
# ap-southeast-2 => Asia Pacific (Sydney) Region | |
# eu-west-1 => EU (Ireland) Region | |
# sa-east-1 => South America (Sao Paulo) Region | |
# us-east-1 => US East (Northern Virginia) Region | |
# us-west-1 => US West (Northern California) Region | |
# us-west-2 => US West (Oregon) Region | |
regions=( "ap-northeast-1" "ap-southeast-1" "ap-southeast-2" "eu-west-1" "sa-east-1" "us-east-1" "us-west-1" "us-west-2" ) | |
cmd="aws ec2 delete-security-group --group-name " | |
if test -z "$1" | |
then | |
echo "Using the default region you've configured for the AWS cli" | |
else | |
echo "You've requested a region: $1" | |
requested_region=$1 | |
valid_region=false | |
for region in "${regions[@]}" | |
do | |
if [ $region == $requested_region ] | |
then | |
valid_region=true | |
fi | |
done | |
if [ $valid_region == true ] | |
then | |
cmd="aws --region $requested_region ec2 delete-security-group --group-name " | |
else | |
echo "The region you requested doesn't exist. Using the default region you've configured for the AWS cli" | |
fi | |
fi | |
# Order to delete the OpsWorks groups | |
# 1 AWS-OpsWorks-Monitoring-Master-Server | |
# 2 AWS-OpsWorks-DB-Master-Server | |
# 3 AWS-OpsWorks-Blank-Server | |
# 4 AWS-OpsWorks-Memcached-Server | |
# 5 AWS-OpsWorks-Custom-Server | |
# 6 AWS-OpsWorks-nodejs-App-Server | |
# 7 AWS-OpsWorks-PHP-App-Server | |
# 8 AWS-OpsWorks-Rails-App-Server | |
# 9 AWS-OpsWorks-Default-Server | |
# 10 AWS-OpsWorks-AWS-Flow-Ruby-Server | |
# 11 AWS-OpsWorks-AWS-Java-App-Server | |
# 12 AWS-OpsWorks-Web-Server | |
# 13 AWS-OpsWorks-LB-Server | |
groups=( "AWS-OpsWorks-Monitoring-Master-Server" "AWS-OpsWorks-DB-Master-Server" "AWS-OpsWorks-Blank-Server" "AWS-OpsWorks-Memcached-Server" "AWS-OpsWorks-Custom-Server" "AWS-OpsWorks-nodejs-App-Server" "AWS-OpsWorks-PHP-App-Server" "AWS-OpsWorks-Rails-App-Server" "AWS-OpsWorks-Default-Server" "AWS-OpsWorks-AWS-Flow-Ruby-Server" "AWS-OpsWorks-Java-App-Server" "AWS-OpsWorks-Web-Server" "AWS-OpsWorks-LB-Server" ) | |
for group in "${groups[@]}" | |
do | |
$cmd $group | |
if [ $? -gt 0 ] | |
then | |
echo "...error removing $group. Subsequent groups will probably fail as well" | |
else | |
echo "...removed $group" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment