Home > database >  How do I quickly list all Google Cloud projects in an organization?
How do I quickly list all Google Cloud projects in an organization?

Time:06-14

I would like to quickly list all Google Cloud projects in an organization, without AppScript folders.

gcloud projects list can be very slow. This documentation is about speeding it up, but does not show how to retrieve the Appscript folder which is used for filtering. Can that be done from the command line?

Also, gcloud projects list does not have a way to filter by organization. It seems that that is impossible as projects are not linked to their organization except through a tree of folders.

The documentation shows a way of walking the tree, apparently with Resource Manager API, which might do the job, but only pseudocode is shown. How can this be done with gcloud -- or else with Python or another language?

And if there is no way to accelerate this: How do I page through results using gcloud projects list? The documentation shows that page-size can be set, but does not show how to step through page by page (presumably by sending a page number with each command).

CodePudding user response:

  • Unfortunately there isn’t a native Apps Script resource available to work with Cloud Resource Manager API.

  • Although, it is possible to make a HTTP call directly to the Resource Manager API projects.list() endpoint with the help of UrlFetchApp service.

  • Alternatively, using Python as mentioned, the recommended Google APIs client library for python supports calls to Resource Manager API. You can find the specific projects.list() method documentation here.

  • On additional note, if you happen to use a Cloud project to generate credentials and authenticate the API call, you may want to enable Cloud Resource Manager API on your project by following this URL.

  • I’d also recommend submitting a new Feature Request using this template.

  • Related