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

不羁的心 提交于 2020-05-08 05:55:08

问题


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?


回答1:


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: https://cloud.google.com/asset-inventory/docs/searching-resources

Searchable resource types: https://cloud.google.com/asset-inventory/docs/supported-asset-types#searchable_asset_types



来源:https://stackoverflow.com/questions/60517563/how-to-find-list-or-search-resources-across-services-apis-and-projects-in-go

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!