Skip to content

Instantly share code, notes, and snippets.

@philpennock
Created February 4, 2022 16:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philpennock/fd6c3bcd94f8e246b6f5063405d95057 to your computer and use it in GitHub Desktop.
Save philpennock/fd6c3bcd94f8e246b6f5063405d95057 to your computer and use it in GitHub Desktop.
Report on AWS free IPs
#!/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