Reputation: 40061
I'm looking for a way to list projects that are not in an Organization (or Folder).
gcloud projects list ...
returns a list of Project and the only obvious indicator that the project is not part of an Organization (or Folder) is the absence of a parent
property.
I've been unable to find a way to --filter
the results to exclude projects without a property.
I discovered the yesno
transform that's part of --format
which, combined with the csv
formatter gives me results that I can then grep
and cut
:
gcloud projects list \
--format='csv[no-heading,separator=":"](parent.yesno(yes="Y",no="N"),projectId)' \
| grep ^N: \
| cut -d: -f2
But I'd like a way to do this solely using gcloud
.
Upvotes: 2
Views: 1036
Reputation: 4660
As talked in the comments, the solution to return the list of projects without an organization is to run a gcloud
command that filter by the parent, using the yesno
option. As clarified in this similar case here, the command that can be used to achieve that is the following.
gcloud projects list --filter="parent.id.yesno(yes='Yes', no='No')=No"
As the parent
is the relation of a project being under an organization, this command filters when a project doesn't have a parent.
Upvotes: 3