简体   繁体   中英

List all GCP projects of an organization using resource manager (Java library)

I'm building an application in Java for getting all the GCP projects and all the resources under the projects of an organization. I saw one option to get all the projects under an organization using resource manager, when I hit through REST API like as shown below

https://cloud.google.com/resource-manager/reference/rest/v1/projects/list

I am able to see all the projects under the organization but when I try the same via java gcp library I am getting only the provided service account project details and not the full organizational projects.

Can someone please help me on this

The following example demonstrates how to list every resource node in your Organizations:

organizations = CloudResourceManager.Organizations.Search()
projects = emptyList()

parentsToList = queueOf(organizations)
while (parent = parentsToList.pop()) {
  // NOTE: Don't forget to iterate over paginated results.
  // TODO: handle PERMISSION_DENIED appropriately.
  projects.addAll(CloudResourceManager.Projects.List(
      "parent.type:" + parent.type + " parent.id:" + parent.id))
  parentsToList.addAll(CloudResourceManager.Folders.List(parent))
}

If your gcloud projects list query fails or takes too long, the number of Google Cloud projects to return might be too large. To fix this, apply the filter and page-size flags to your gcloud projects list command.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM