Last active
October 22, 2021 13:07
-
-
Save wilhelm-murdoch/b4fbc4cf40aafb912b8ef56828aba8e7 to your computer and use it in GitHub Desktop.
List all unused security groups in all AWS regions ...
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 | |
set -eo pipefail | |
[[ -n "${VERBOSE}" ]] && set -x | |
for region in $(aws ec2 describe-regions | jq -r '.Regions[].RegionName'); do | |
for sg in $(aws ec2 describe-security-groups --region="${region}" | jq -r '.SecurityGroups[].GroupId'); do | |
if [[ $(aws ec2 describe-network-interfaces --region="${region}" --filters Name=group-id,Values="${sg}" | jq -r '.NetworkInterfaces | length') -eq 0 ]]; then | |
echo "${sg} in ${region}" | |
fi | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment