Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieve project id from Google Compute Engine machine?

I have two Google Cloud Platform projects (staging and production). I would like my application deployed on Google Compute Engine instance to automatically detected the project id. What is the way to do it?

like image 551
poiuytrez Avatar asked Sep 05 '26 19:09

poiuytrez


1 Answers

You can query the metadata server programmatically for a variety of information, including the project id.

For the project id:

$ curl "http://metadata.google.internal/computeMetadata/v1/project/project-id" -H "Metadata-Flavor: Google"

This will return your project id, eg: my-gcp-project

Or if you need the numeric project id:

$ curl "http://metadata.google.internal/computeMetadata/v1/project/numeric-project-id" -H "Metadata-Flavor: Google"

This will return the numeric project id, eg: 0123456789

like image 171
Paul Rossman Avatar answered Sep 07 '26 16:09

Paul Rossman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!