如何在 Google Cloud Platform 中跨服务 (API) 和项目查找、列出或搜索资源?

How to find, list, or search resources across services (APIs) and projects in Google Cloud Platform?

在 Google 云平台 (GCP) 中,您可以使用列表 API 或命令列出给定项目中给定服务中给定类型的资源,例如 BigQuery 数据集或计算实例。

但是如何跨类型、跨服务甚至跨项目查找或搜索资源?

您可以使用 search-all-resources 跨服务(或 API)和项目搜索给定组织、文件夹或项目的所有资源。

搜索编号为123的项目中的所有资源:

$ gcloud asset search-all-resources --scope=projects/123

限制为仅计算资源:

$ gcloud asset search-all-resources --scope=projects/123 --query="compute.googleapis.com"

限制为仅包含“foo”作为子字符串的资源:

$ gcloud asset search-all-resources --scope=projects/123 --query="*foo*"

列出组织内的所有项目 456:

$ gcloud asset search-all-resources --scope=organizations/456 --asset-types=cloudresourcemanager.googleapis.com/Project

查找组织 456 中包含“foo”作为子字符串的所有 BigQuery 数据集:

$ gcloud asset search-all-resources --scope=organizations/456 --query="bigquery datasets *foo*"

您可以将范围设置为项目、文件夹或组织。

要使用该命令,您必须:

  • 启用Cloud Asset API,并且

  • 对以下角色中包含的范围具有 cloudasset.assets.searchAllResources 权限:

    • roles/cloudasset.观众
    • roles/cloudasset.所有者
    • roles/viewer
    • roles/editor
    • roles/owner

文档: