Search code examples
google-cloud-platformgcloudgoogle-cloud-resource-manager

How do I get the organization ID of my current project in Google Cloud Platform?


I would like to know the organization ID of my current project in GCP.

gcloud projects describe PROJECT_ID will show the parent which can be the organization, but if the parent is a folder, the organization ID does not appear.

I could recurse up the parent hierarchy of the folders using gcloud resource-manager folders describe FOLDER_ID, but that is a hassle. It is also impossible if I do not have organization-level permissions.

Yet I do have access to organization IDs: gcloud organizations list shows several organizations, though not their mapping to projects.

How can I achieve this?


Solution

  • Use the below gcloud command in cloud shell.

    gcloud projects get-ancestors {projectId}
    

    This should give the output as below.

    ID                      TYPE
    Your-project-ID         project
    123456789012            folder
    567890123456            organization