Reputation: 2616
gcloud allows you to list organization, folders or projects. I didn't found a option to list projects inside a organization.
Something like:
gcloud projects list --organization=ORG
Upvotes: 3
Views: 14458
Reputation: 3867
The literal proposed solution is in the gcloud alpha track now, four years later. So probably someday it'll be mainstream. :)
gcloud alpha projects list --organization 123789
Upvotes: 0
Reputation: 15707
Not what you asked, but if you want to filter to all projects assigned to a folder you can use --filter='parent.id:40123456789'
:
$ gcloud organizations list
DISPLAY_NAME ID DIRECTORY_CUSTOMER_ID
example.com 10123456789 C0123abc
$ gcloud resource-manager folders list --organization=10123456789
DISPLAY_NAME PARENT_NAME ID
demos organizations/10123456789 40123456789
test organizations/10123456789 50123456789
$ gcloud projects list --filter='parent.id:40123456789'
PROJECT_ID NAME PROJECT_NUMBER
demo-one demo-one 301123456789
demo-two demo-two 302123456789
demo-three demo-three 303123456789
Upvotes: 1
Reputation: 9
You can use gcloud:
gcloud projects list --filter 'parent.id=id-organization123456 AND parent.type=organization' | awk '{print $1 }' > projects.txt
Upvotes: 0
Reputation: 75775
You can use Cloud Asset inventory. The base query is the following:
gcloud beta asset search-all-resources \
--asset-types=cloudresourcemanager.googleapis.com/Project \
--scope=organizations/920778098964
You can play with page size if you want to have a long list of results. More details here
I personally prefer to export to BigQuery all the assets and then query what I want in it. Project, but also VM, firewall rules,....
Upvotes: 5
Reputation: 1225
I think there's no quick way like you mentioned with --organization
arg, but that could be accomplished with, for example, the following UNIX-like script:
for project_id in $(gcloud projects list --format='value(project_id)'); do
org_id=$(gcloud projects describe $project_id --format='value(parent.id)')
if [ $org_id -eq $the_org_you_want_to_find_out ]; then
echo "$org_id > $project_id"
fi
done
Upvotes: 1
Reputation: 353
You could list all the project in an organization using the following command:
gcloud projects list
The definition of the command is:
Lists all active projects, where the active account has Owner, Editor or Viewer permissions. Projects are listed in alphabetical order by project name. Projects that have been deleted or are pending deletion are not included.
If you only need the project_ID, the name or the project number you could use:
gcloud projects list --format 'value(project_id)'
gcloud projects list --format 'value(name)'
gcloud projects list --format 'value(project_number)'
Upvotes: -1