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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With