如何在Google Cloud Platform中跨服务(API)和项目查找,列出或搜索资源? [英] How to find, list, or search resources across services (APIs) and projects in Google Cloud Platform?

本文介绍了如何在Google Cloud Platform中跨服务(API)和项目查找,列出或搜索资源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

但是如何在类型,服务甚至项目之间查找或搜索资源?

解决方案

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

要搜索编号为123的项目中的所有资源,请执行以下操作:

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

要限制为仅计算资源:

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

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

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

要列出组织456中的所有项目,请执行以下操作:

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

要查找所有包含"foo"的BigQuery数据集,请执行以下操作:作为组织456中的子字符串:

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

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

要使用该命令,您必须:

  • 启用 Cloud Asset API ,并

  • 对作用域具有cloudasset.assets.searchAllResources权限,这些权限包括在这些角色中:

    • roles/cloudasset.viewer
    • roles/cloudasset.owner
    • 角色/查看器
    • 角色/编辑器
    • 角色/所有者

文档:

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?

解决方案

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 beta asset search-all-resources --scope=projects/123

To limit to only compute resources:

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

To limit to only resources containing "foo" as a sub string:

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

To list all the projects within an organization 456:

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

To find all the BigQuery datasets containing "foo" as a sub string within an organization 456:

$ gcloud beta 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:

  • Enable Cloud Asset API, and

  • Have cloudasset.assets.searchAllResources permission upon the scope, which is included in these roles:

    • roles/cloudasset.viewer
    • roles/cloudasset.owner
    • roles/viewer
    • roles/editor
    • roles/owner

Documentation:

这篇关于如何在Google Cloud Platform中跨服务(API)和项目查找,列出或搜索资源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆