[英]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.