google-cloud-platformgoogle-compute-enginegcloudgce-instance-group

List internal IP addresses of GCE Instance groups


I was trying to automate outputting the Internal IP Addresses of instances that are created as part of Managed Instance groups (MIG) in Google cloud Compute engine. This was the closest documentation I could see: https://cloud.google.com/compute/docs/instances/view-ip-address#gcloud


Solution

  • For MIGs (no external IP) created for a Region:

    gcloud compute instance-groups list-instances my-test-ig-regional \
    --region=us-central1 \
    --uri | xargs -I '{}' gcloud compute instances describe '{}' \
    --flatten networkInterfaces \
    --format 'csv[no-heading](name,networkInterfaces.networkIP)'
    

    For MIGs (no external IP) created for a zone:

    gcloud compute instance-groups list-instances my-test-ig-zonal \
    --zone=us-central1-a \
    --uri | xargs -I '{}' gcloud compute instances describe '{}' \
    --flatten networkInterfaces \
    --format 'csv[no-heading](name,networkInterfaces.networkIP)'