Real-time IP capacity in Google Cloud subnets
When managing Shared VPCs, most teams allocate dedicated IP subnets for each service project to keep firewall rules simple, but this isolation often leads to poor IP utilization — it is not uncommon to see subnet IP utilization hovering in the low teens. On the other hand, using large shared subnets requires coordinating workload deployments to ensure there is enough internal IP address space for everyone. To optimize these shared networks, you need real-time visibility. The WITH_UTILIZATION query parameter on the Method: subnetworks.list | Compute Engine API solves this by returning the exact count of allocated and free IP addresses for each subnet IP range. This capability is designed for query-time decisions. For example, if you need to deploy a GCE workload requiring 100 instances, you can search for a subnet with enough capacity. This query-time data comes directly from Google Cloud's internal IP allocator and includes both primary and secondary CIDR ranges. Automating the search with gcloud and jq To automate capacity checks before you deploy, you can script this check. The script below uses gcloud compute networks subnets list | Google Cloud SDK to grab the utilization data as JSON, and then uses jq to parse, filter, and sort the subnets based on your required capacity: #!/bin/bash # --- Configuration (Replace with your details) --- PROJECT = "<YOUR_PROJECT_ID>" NETWORK_NAME = "<YOUR_VPC_NETWORK_NAME>" REGION = "<YOUR_REGION>" REQUIRED_IP_CAPACITY = 100 echo "Searching $NETWORK_NAME in $REGION for subnets with >= $REQUIRED_IP_CAPACITY free IPs..." echo "------------------------------------------------------------------------" # Fetch subnets with utilization data, output as JSON, and pipe to jq gcloud compute networks subnets list \ --project = " $PROJECT " \ --network = " $NETWORK_NAME " \ --regions = " $REGION " \ --view = WITH_UTILIZATION \ --format = json | \ jq -r --argjson min_ips " $REQUIRED_IP_CAPACITY " ' [ .[] | { name: .name, cidr: .ipCidrRange, #