如何在 Google Cloud Platform 中跨服务 (API) 和项目查找、列出或搜索资源? [英] How to find, list, or search resources across services (APIs) and projects in Google Cloud Platform?
问题描述
在 Google Cloud Platform (GCP) 中,您可以使用列表 API 或命令列出给定服务中给定类型的给定项目中的资源,例如 BigQuery 数据集或计算实例.
In Google Cloud Platform (GCP), you can use list APIs or commands to list resources in a given project for a given type in a given service, like BigQuery datasets or compute instances.
但是如何跨类型、跨服务甚至跨项目查找或搜索资源?
But how to find or search resources across types, services, or even projects?
推荐答案
您可以使用 search-all-resources 来搜索给定组织、文件夹或项目的跨服务(或 API)和项目的所有资源.
You can use search-all-resources to search all the resources across services (or APIs) and projects for a given organization, folder, or project.
>
要搜索项目中编号为 123 的所有资源:
To search all the resources in a project with number 123:
$ gcloud asset search-all-resources --scope=projects/123
限制为仅计算资源:
$ gcloud asset search-all-resources --scope=projects/123 --query="compute.googleapis.com"
限制为仅包含foo"的资源作为子字符串:
To limit to only resources containing "foo" as a sub string:
$ gcloud asset search-all-resources --scope=projects/123 --query="*foo*"
要列出组织内的所有项目 456:
To list all the projects within an organization 456:
$ gcloud asset search-all-resources --scope=organizations/456 --asset-types=cloudresourcemanager.googleapis.com/Project
要查找包含foo"的所有 BigQuery 数据集,请执行以下操作:作为组织内的子字符串 456:
To find all the BigQuery datasets containing "foo" as a sub string within an organization 456:
$ gcloud asset search-all-resources --scope=organizations/456 --query="bigquery datasets *foo*"
您可以将范围设置为项目、文件夹或组织.
You can set the scope to a project, a folder or an organization.
要使用该命令,您必须:
To use the command, you must:
启用 云资产 API,以及
对包含在这些角色中的范围拥有 cloudasset.assets.searchAllResources
权限:
Have cloudasset.assets.searchAllResources
permission upon the scope, which is included in these roles:
- roles/cloudasset.viewer
- roles/cloudasset.owner
- 角色/查看者
- 角色/编辑
- 角色/所有者
文档:
- 更多 gcloud 示例:https://cloud.google.com/asset-inventory/docs/searching-resources-samples
- 指南:https://cloud.google.com/asset-inventory/docs/searching-resources
- 可搜索的资源类型:https://cloud.google.com/asset-inventory/docs/supported-asset-types#searchable_asset_types
这篇关于如何在 Google Cloud Platform 中跨服务 (API) 和项目查找、列出或搜索资源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!