Method: searchAllResources

Searches all Cloud resources within the specified scope, such as a project, folder, or organization. The caller must be granted the cloudasset.assets.searchAllResources permission on the desired scope, otherwise the request will be rejected.

HTTP request

GET https://cloudasset.googleapis.com/v1/{scope=*/*}:searchAllResources

The URL uses gRPC Transcoding syntax.

Path parameters

Parameters
scope

string

Required. A scope can be a project, a folder, or an organization. The search is limited to the resources within the scope. The caller must be granted the cloudasset.assets.searchAllResources permission on the desired scope.

The allowed values are:

  • projects/{PROJECT_ID} (e.g., "projects/foo-bar")
  • projects/{PROJECT_NUMBER} (e.g., "projects/12345678")
  • folders/{FOLDER_NUMBER} (e.g., "folders/1234567")
  • organizations/{ORGANIZATION_NUMBER} (e.g., "organizations/123456")

Authorization requires the following IAM permission on the specified resource scope:

  • cloudasset.assets.searchAllResources

Query parameters

Parameters
query

string

Optional. The query statement. See how to construct a query for more information. If not specified or empty, it will search all the resources within the specified scope. Note that the query string is compared against each Cloud IAM policy binding, including its members, roles, and Cloud IAM conditions. The returned Cloud IAM policies will only contain the bindings that match your query. To learn more about the IAM policy structure, see IAM policy doc.

Examples:

  • name:Important to find Cloud resources whose name contains "Important" as a word.
  • displayName:Impor* to find Cloud resources whose display name contains "Impor" as a prefix.
  • description:*por* to find Cloud resources whose description contains "por" as a substring.
  • location:us-west* to find Cloud resources whose location is prefixed with "us-west".
  • labels:prod to find Cloud resources whose labels contain "prod" as a key or value.
  • labels.env:prod to find Cloud resources that have a label "env" and its value is "prod".
  • labels.env:* to find Cloud resources that have a label "env".
  • Important to find Cloud resources that contain "Important" as a word in any of the searchable fields.
  • Impor* to find Cloud resources that contain "Impor" as a prefix in any of the searchable fields.
  • *por* to find Cloud resources that contain "por" as a substring in any of the searchable fields.
  • Important location:(us-west1 OR global) to find Cloud resources that contain "Important" as a word in any of the searchable fields and are also located in the "us-west1" region or the "global" location.
assetTypes

string

Optional. A list of asset types that this request searches for. If empty, it will search all the searchable asset types.

pageSize

integer

Optional. The page size for search result pagination. Page size is capped at 500 even if a larger value is given. If set to zero, server will pick an appropriate default. Returned results may be fewer than requested. When this happens, there could be more results as long as nextPageToken is returned.

pageToken

string

Optional. If present, then retrieve the next batch of results from the preceding call to this method. pageToken must be the value of nextPageToken from the previous response. The values of all other method parameters, must be identical to those in the previous call.

orderBy

string

Optional. A comma separated list of fields specifying the sorting order of the results. The default order is ascending. Add " DESC" after the field name to indicate descending order. Redundant space characters are ignored. Example: "location DESC, name". Only string fields in the response are sortable, including name, displayName, description, location. All the other fields such as repeated fields (e.g., networkTags), map fields (e.g., labels) and struct fields (e.g., additionalAttributes) are not supported.

Request body

The request body must be empty.

Response body

If successful, the response body contains data with the following structure:

Search all resources response.

JSON representation
{
  "results": [
    {
      object (ResourceSearchResult)
    }
  ],
  "nextPageToken": string
}
Fields
results[]

object (ResourceSearchResult)

A list of Resources that match the search query. It contains the resource standard metadata information.

nextPageToken

string

If there are more results than those appearing in this response, then nextPageToken is included. To get the next set of results, call this method again using the value of nextPageToken as pageToken.

Authorization Scopes

Requires the following OAuth scope:

  • https://www.googleapis.com/auth/cloud-platform

For more information, see the Authentication Overview.

ResourceSearchResult

A result of Resource Search, containing information of a cloud resource.

JSON representation
{
  "name": string,
  "assetType": string,
  "project": string,
  "displayName": string,
  "description": string,
  "location": string,
  "labels": {
    string: string,
    ...
  },
  "networkTags": [
    string
  ],
  "additionalAttributes": {
    object
  }
}
Fields
name

string

The full resource name of this resource. Example: //compute.googleapis.com/projects/my_project_123/zones/zone1/instances/instance1. See Cloud Asset Inventory Resource name Format for more information.

To search against the name:

  • use a field query. Example: name:instance1
  • use a free text query. Example: instance1
assetType

string

The type of this resource. Example: compute.googleapis.com/Disk.

To search against the assetType:

  • specify the assetType field in your search request.
project

string

The project that this resource belongs to, in the form of projects/{PROJECT_NUMBER}.

To search against the project:

  • specify the scope field as this project in your search request.
displayName

string

The display name of this resource.

To search against the displayName:

  • use a field query. Example: displayName:"My Instance"
  • use a free text query. Example: "My Instance"
description

string

One or more paragraphs of text description of this resource. Maximum length could be up to 1M bytes.

To search against the description:

  • use a field query. Example: description:"*important instance*"
  • use a free text query. Example: "*important instance*"
location

string

Location can be global, regional like us-east1, or zonal like us-west1-b.

To search against the location:

  • use a field query. Example: location:us-west*
  • use a free text query. Example: us-west*
labels

map (key: string, value: string)

Labels associated with this resource. See Labelling and grouping GCP resources for more information.

To search against the labels:

  • use a field query:
    • query on any label's key or value. Example: labels:prod
    • query by a given label. Example: labels.env:prod
    • query by a given label's existence. Example: labels.env:*
  • use a free text query. Example: prod

An object containing a list of "key": value pairs. Example: { "name": "wrench", "mass": "1.3kg", "count": "3" }.

networkTags[]

string

Network tags associated with this resource. Like labels, network tags are a type of annotations used to group GCP resources. See Labelling GCP resources for more information.

To search against the networkTags:

  • use a field query. Example: networkTags:internal
  • use a free text query. Example: internal
additionalAttributes

object (Struct format)

The additional searchable attributes of this resource. The attributes may vary from one resource type to another. Examples: projectId for Project, dnsName for DNS ManagedZone. This field contains a subset of the resource metadata fields that are returned by the globalOperations.list or globalOperations.get APIs provided by the corresponding GCP service (e.g., Compute Engine). see API references and supported searchable attributes for more information.

You can search values of these fields through free text search. However, you should not consume the field programically as the field names and values may change as the GCP service updates to a new incompatible API version.

To search against the additionalAttributes:

  • use a free text query to match the attributes values. Example: to search additionalAttributes = { dnsName: "foobar" }, you can issue a query foobar.