是否可以通过gcloud cli列出给定GCP项目下的所有活动资源?
答案 0 :(得分:8)
您可以使用search-all-resources来搜索给定组织,文件夹或项目中跨服务(或API)和项目的所有资源。
要搜索编号为123的项目中的所有资源:
$ gcloud asset search-all-resources --scope=projects/123
这是gcloud alpha resources list
的GA版本。
有关其他详细信息,请参见其他文章: How to find, list, or search resources across services (APIs) and projects in Google Cloud Platform?
答案 1 :(得分:6)
我认为该命令可以做到,但是似乎只在封闭的alpha中使用,所以我认为在不久的将来...
gcloud alpha资源列表
https://cloud.google.com/sdk/gcloud/reference/alpha/resources/list
答案 2 :(得分:2)
IIUC没有用于“项目中存在的事物”的通用类型,因此您需要专门枚举所有(您感兴趣的)类型。
此外,某些资源(例如密钥)由项目拥有的服务帐户拥有。
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
使用此方法的各种挑战:
NB
--filter=...
应用于上述每个命令gcloud auth list
个帐户的循环