Created
February 4, 2022 16:53
-
-
Save philpennock/fd6c3bcd94f8e246b6f5063405d95057 to your computer and use it in GitHub Desktop.
Report on AWS free IPs
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
#!/bin/sh -eu | |
: "${VPC_ID:=}" | |
ShowVPCPrefix='' | |
format_subnets() { | |
jq -r '.Subnets[] | |
| "'"${ShowVPCPrefix}"'\(.AvailabilityZone)\t\(.SubnetId)\t\(.CidrBlock)\t\(.AvailableIpAddressCount)\t\( | |
if .Tags then .Tags[]|select(.Key=="Name")|.Value else "<none>" end)"' | | |
sort | |
} | |
if [ ".$VPC_ID" = ".all" ]; then | |
VPC_ID='' | |
ShowVPCPrefix='\(.VpcId)\t' | |
fi | |
if [ ".$VPC_ID" != "." ]; then | |
get_subnets() { aws ec2 describe-subnets --filters "Name=vpc-id,Values=[${VPC_ID}]"; } | |
else | |
get_subnets() { aws ec2 describe-subnets; } | |
fi | |
get_subnets | format_subnets |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment