Last active
August 29, 2015 14:14
-
-
Save mrowe/6872a69e6aa5cd9dc3c0 to your computer and use it in GitHub Desktop.
Find unused security groups
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 ruby | |
require 'aws-sdk' | |
ec2 = AWS::EC2.new | |
elb = AWS::ELB.new | |
rds = AWS::RDS.new.client # shrug | |
security_groups = ec2.security_groups.map { |sg| sg.id }.sort | |
instance_sgs = ec2.instances.map { |i| i.security_groups.map { |sg| sg.id } }.flatten.sort | |
elb_sgs = elb.load_balancers.map { |elb| elb.security_groups.map { |sg| sg.id } }.flatten.sort | |
rds_sgs = rds.describe_db_instances.db_instances.map { |db| db.vpc_security_groups.map { |sg| sg.vpc_security_group_id } }.flatten.sort | |
puts security_groups - instance_sgs - elb_sgs - rds_sgs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment