I am trying to filter out an external IP address used by a Router. When I run the address list command, there is no way I can filter with name as it is auto-created by NAT:
gcloud compute addresses list
NAME ADDRESS/RANGE TYPE PURPOSE NETWORK REGION SUBNET STATUS
test-network-1234 10.xxx.0.0/18 INTERNAL VPC_PEERING test-network-gcp-1 RESERVED
test-network-abcd 10.xxx.xx.0/18 INTERNAL VPC_PEERING test-network-gcp-1 RESERVED
nat-auto-ip-15564773-5-xx xx.xxx.xx.x EXTERNAL NAT_AUTO IN_USE
In the console I can see 'In use by' 'Router abcd' column. Is there any way I can filter using this 'In use' parameter?
EDIT: Added Screenshot of console
EDIT: Found this, like other GCP values, the 'in use by' column as represented by users (as given in this reponse-body ) is given as an API URL.
So I had to create a URL and pass the below values:
api_url="https://www.googleapis.com/compute/v1/projects/${landscape_project}/regions/${landscape_region}/routers/${router_name}"
external_ip="$(gcloud compute addresses list --filter="users=('${api_url}')" --format=json | jq -r '.[].address')"
This way I was able to pass the router_name and create the API URL and pass it as filter to get the external IP.
Hope this helps someone
Cheers!