Query Instance Metadata on Google Cloud

I needed my web server to dynamically find the database instance in my Google Cloud project. Yes, I could use DNS, or environment variables. Instead, I just wanted to look it up at runtime via a start script.

The only magic here was getting the format string correct.

gcloud compute instances list  --project nicks-project --filter="tags:db" \ 
--format='value[](networkInterfaces[].networkIP.notnull().list():label=INTERNAL_IP)'

Done!


comments powered by Disqus