Reputation: 930
Is it possible to list, through the Google Cloud Platform (GCP) SDK CLI (gcloud
), all active resources under a given GCP project?
Upvotes: 33
Views: 20600
Reputation: 31
If you want to list the resources on basis of their state then you can use --filter=
option and this will the active state resources
Use Case:- If you want to list all the projects with pending deletion state then you will use:
gcloud projects list --filter='lifecycleState:DELETE_REQUESTED'
Upvotes: 0
Reputation: 1194
You can use search-all-resources to search all the resources across services (or APIs) and projects for a given organization, folder, or project.
To search all the resources in a project with number 123:
$ gcloud asset search-all-resources --scope=projects/123
See the other post for more details: How to find, list, or search resources across services (APIs) and projects in Google Cloud Platform?
Upvotes: 29
Reputation: 40426
IIUC there's no general-purpose type for "things that live in projects" so you'd need to enumerate all the types (that interest you) specifically.
Also, some resources (e.g. keys) are owned by service accounts that are owned by projects.
for PROJECT in $(\
gcloud projects list \
--format="value(projectId)")
do
echo "Project: ${PROJECT}"
echo "Services"
gcloud services list --project=${PROJECT}
echo "Kubernetes Clusters"
gcloud container clusters list --project=${PROJECT}
echo "Compute Engine instances"
gcloud compute instances list --project=${PROJECT}
echo "Service Accounts"
for ACCOUNT in $(\
gcloud iam service-accounts list \
--project=${PROJECT} \
--format="value(email)")
do
echo "Service Account keys: ${ACCOUNT}"
gcloud iam service-accounts keys list --iam-account=${ACCOUNT} --project=${PROJECT}
done
done
Various challenges with this approach though:
NB
--filter=...
to each of the above commandsgcloud auth list
accountsUpvotes: 6