Last active
March 27, 2023 15:29
-
-
Save marknca/6324493 to your computer and use it in GitHub Desktop.
Remove OpsWorks security groups from a given region
This file contains hidden or 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-Web-Server | |
# 11 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-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
I thinks OpsWorks is fantastic but it does do one thing that drives me crazy. When you enable it, it creates a set of 11 EC2 security groups in all AWS regions. There are quite a few dependencies between the groups so you have to remove them in order...of course I can never remember the order.
No idea why it bugs me so much but mine is not to question just to solve with a tiny shell script.
Usage;