Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Google Cloud Project Number using its Id

I have Google Cloud Service account and projectId and want to get projectNumber programmatically from Java.

enter image description here

How can I get it?

Basically I have Service Account and want to use it for granting role "roles/storage.legacyBucketWriter" for the account "[email protected]" in the Google Cloud Storage Bucket.

like image 389
Dmitry Gorkovets Avatar asked Sep 13 '18 05:09

Dmitry Gorkovets


People also ask

What is the use of project ID in GCP?

The project ID is a unique identifier for a project and is used only within the console. When you first create a project, you can accept the default generated project ID or create your own.

How do I check my gcloud project?

To see all your gcloud projects you use command gcloud projects list . To switch to a specific project, you use gcloud config set project PROJECT_ID .

How do I find the owner of the GCP project?

To confirm who owns the project, go to the Google Cloud Platform Console, open the console left side menu, and click IAM & Admin. Ensure that a project is selected to see the project owner.


1 Answers

Not sure why they don't expose it directly, but you can do this (assuming your current configuration project corresponds to the desired project number):

gcloud projects list \
--filter="$(gcloud config get-value project)" \
--format="value(PROJECT_NUMBER)"
like image 129
erkolson Avatar answered Sep 25 '22 17:09

erkolson