简体   繁体   English

如何在 Google Cloud Platform 中获取当前项目的组织 ID?

[英]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.我想知道我在 GCP 中当前项目的组织 ID。

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. gcloud projects describe PROJECT_ID将显示可以是组织的parent级,但如果父级是folder ,则不会显示组织 ID。

I could recurse up the parent hierarchy of the folders using gcloud resource-manager folders describe FOLDER_ID , but that is a hassle.我可以使用gcloud resource-manager folders describe FOLDER_ID递归文件夹的父层次结构,但这很麻烦。 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.然而,我确实可以访问组织 ID: gcloud organizations list显示了几个组织,尽管它们没有映射到项目。

How can I achieve this?我怎样才能做到这一点?

If we read here we find that your organization is the root of the ancestor tree of your current project.如果我们在这里阅读,我们会发现您的组织是您当前项目的祖先树的根。

We also find that there is an API that can be called to retrieve the ancestry chain from a given project upwards.我们还发现可以调用一个 API 来从给定项目向上检索祖先链。 This means that we can retrieve the organization id of your project using that API.这意味着我们可以使用该 API 检索您项目的组织 ID。

The API is documented here . API 记录在这里

It has the high level REST format of:它具有以下高级 REST 格式:

POST https://cloudresourcemanager.googleapis.com/v1/projects/{projectId}:getAncestry

A possible command might be:一个可能的命令可能是:

curl -X POST -H "Authorization: Bearer \"$(gcloud auth application-default print-access-token)\"" \
          -H "Content-Type: application/json; charset=utf-8" \
             https://cloudresourcemanager.googleapis.com/v1/projects/<MY_PROJECT>:getAncestry

Use the below gcloud command in cloud shell.在 cloud shell 中使用以下 gcloud 命令。

gcloud projects get-ancestors {projectId}

This should give the output as below.这应该给出如下输出。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我的Google Cloud Platform是否需要一个组织 - Do I need an Organization in my Google Cloud Platform 如何在 Google Cloud Platform 上为我的组织禁用结算帐户创建? - How do I disable Billing Account Creation for my organization on Google Cloud Platform? 如何使用 Go SDK for Google Cloud Platform 获取项目 ID? - How to get project ID using Go SDK for Google cloud platform? Google Cloud Platform 项目配额 - 按组织或组织中的用户或两者 - Google Cloud Platform project quotas - By organization or by user in the organization or both Google Cloud Platform - 将“无组织”的 firebase 项目移至“组织”时出错 - Google Cloud Platform - Error moving firebase project with "no organization" to an "organization" 我如何知道我在谷歌云平台上的区域 ID 是什么 - How do i know what is my region ID on google cloud platform Google Cloud Platform:如何重命名 Google Cloud Platform 项目? - Google Cloud Platform: How do I rename a Google Cloud Platform project? 如何在Google Cloud Platform上托管Django项目? - How do I host a Django project on Google Cloud Platform? 如何以编程方式在 Google 云运行 api 中获取当前项目 ID - How to programmatically get current project id in Google cloud run api Google Cloud Platform:如何查找项目的 A 记录? - Google Cloud Platform: How do I find an A record for a project?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM