gcp-assets
Search resources under Google Cloud projects, folders or organizations using Cloud Asset Inventory API.
Syntax
Options
- profile=STRING
- Optional. Google Cloud connect profile. If multiple profiles are separated by commas, each profile is queried in turn and distinguished by the profile field. If not specified, all Google Cloud connect profiles you can use are queried. If an error occurs on a profile, rows already returned remain, the remaining profiles are skipped and the query ends with an error.
- scope=STRING
- Optional.
projects/{id}(orprojects/{number}),folders/{number}ororganizations/{number}. Resources in the scope and below it (including sub folders and projects) are returned. Project of JSON key is used if not specified. - types=STRING
- Optional. Comma separated asset types. Regular expression is supported. e.g.
compute.googleapis.com/Instance,iam.googleapis.com/.*. All types are returned if not specified. See the asset type table in Description for common types. - query=STRING
- Optional. Search query of Cloud Asset Inventory. e.g.
labels.env:prod,location:asia-northeast3,name:sinks. Terms containing characters other than English letters and digits must be enclosed in double quotes, written as\"in the option value. e.g.query="tagKeys:\"dev-team\"". See Cloud Asset Inventory query syntax. - limit=INT
- Optional. Max number of rows per profile. Positive integer. All rows are returned if not specified.
- verbose=BOOL
- Optional. Include versioned_resources and attached_resources.
t,f,trueorfalse(default:f)
Output fields
| Field | Type | Name | Description |
|---|---|---|---|
| profile | String | Profile | Connect profile name |
| asset_type | String | Asset type | e.g. compute.googleapis.com/Instance |
| display_name | String | Display name | Display name of the resource |
| project_id | String | Project ID | User assigned project ID. Empty if the resource does not belong to a project (e.g. organization or folder) |
| project_name | String | Project name | Display name of the project. Empty if the resource does not belong to a project (e.g. organization or folder) |
| location | String | Location | e.g. global, us-central1 |
| state | String | State | State of the resource. e.g. RUNNING, ACTIVE, ENABLED |
| create_time | Date | Created at | Create time of the resource. Only resources that provide it have a value |
| update_time | Date | Updated at | Last update time of the resource. Only resources that provide it have a value |
| name | String | Name | Full resource name. e.g. //compute.googleapis.com/projects/p1/zones/z1/instances/i1 |
| description | String | Description | Description of the resource. Only resources with a description have a value |
| labels | Map | Labels | User defined labels |
| tags | List | Tags | Tags directly attached to the resource. Each item has tagKey, tagKeyId, tagValue and tagValueId |
| effective_tags | List | Effective tags | Tags attached or inherited from ancestors, grouped by attachedResource |
| network_tags | List | Network tags | Network tags of Compute Engine resources |
| kms_keys | List | KMS keys | Cloud KMS keys used to encrypt the resource |
| project | String | Project | Project in projects/{number} form. Empty for organization and folder resources |
| folders | List | Folders | Ancestor folders in folders/{number} form, nearest first |
| organization | String | Organization | Organization in organizations/{number} form |
| parent_asset_type | String | Parent type | Asset type of the parent |
| parent_full_resource_name | String | Parent | Full resource name of the parent |
| additional_attributes | Map | Additional attributes | Asset type specific attributes. e.g. projectId of a project |
| versioned_resources | List | Versioned resources | Full configuration of the resource by API version, as returned by Cloud Asset Inventory. Only with verbose=t |
| attached_resources | List | Attached resources | Attached resources such as Compute Engine OS inventory, as returned by Cloud Asset Inventory. Only with verbose=t |
Error codes
Parse errors
| Error message | Cause | Solution |
|---|---|---|
| No available Google Cloud profile found. | Wrong profile code or no permission to use the profile | Specify the connect profile code in the profile option and check the profile permission |
| Invalid scope: {scope} | Invalid scope format, or a folder or organization specified by name | Specify an ID or number after projects/, folders/ or organizations/ |
| limit should be positive integer: {limit} | limit is 0 or less, or not a number | Specify a positive integer |
| verbose should be t, f, true or false: {verbose} | Invalid verbose value | Specify t, f, true or false |
Runtime errors
| Error message | Cause | Solution |
|---|---|---|
| HTTP 403: PERMISSION_DENIED - The caller does not have permission | No Cloud Asset Viewer role on the scope | Check with gcp-check-permissions and grant the role on the scope |
| HTTP 403: PERMISSION_DENIED - Cloud Asset API has not been used in project ... | Cloud Asset API is not enabled in the project of the service account | Enable Cloud Asset API in the project the service account belongs to |
| HTTP 400: INVALID_ARGUMENT - Invalid query syntax, Unsupported field: ... | Invalid query syntax or unsupported field | Fix the query referring to the supported fields in the message and the query syntax document |
| HTTP 400: INVALID_ARGUMENT - Please quote term ... with double quotes | A query term with special characters is not quoted | Enclose the term with " |
| HTTP 400: INVALID_ARGUMENT - No supported asset type matches: ... | types contains an unsupported or unknown asset type | Check the supported asset types |
| token exchange failed, HTTP 400: Invalid grant | Wrong JSON key, or the service account or key was deleted | Create a new key and update the connect profile |
Description
Searches resource metadata in the scope using searchAllResources API of Cloud Asset Inventory. If an organization or folder is specified, resources in all folders and projects below it are returned. Results are fetched up to 500 at a time until the end.
The API returns the containing project as a number (projects/{number}) only. To make it readable, the command queries projects in the same scope once more and fills project_id and project_name. Folders and organization are returned as numbers only (folders, organization). To find their names, query with types="cloudresourcemanager.googleapis.com/(Folder|Organization)".
Specify IDs or numbers, not display names, in scope. Display names of folders and projects may be duplicated or changed, so specifying a name could query an unintended scope. Use the following query to find organization and folder numbers.
gcp-assets profile=gcp types="cloudresourcemanager.googleapis.com/(Organization|Folder|Project)"
| fields asset_type, display_name, name, organization
query is passed to Google Cloud as is without validation in the app. For an invalid query, Google Cloud returns an INVALID_ARGUMENT error with the cause, which is shown as the query error.
With verbose=t, the full configuration that differs by asset type is also returned, so the response gets larger. For a large scope, increase the read timeout of the connect profile or narrow the scope with types.
Common asset types
Frequently used asset types for the types option. See Supported asset types for the full list. An unknown or misspelled type causes a No supported asset type matches error.
| Category | Asset type | Resource |
|---|---|---|
| Compute | compute.googleapis.com/Instance | VM instance |
| Compute | compute.googleapis.com/Disk | Persistent disk |
| Compute | container.googleapis.com/Cluster | GKE cluster |
| Compute | run.googleapis.com/Service | Cloud Run service |
| Compute | cloudfunctions.googleapis.com/Function | Cloud Functions (2nd gen) |
| Network | compute.googleapis.com/Firewall | Firewall rule |
| Network | compute.googleapis.com/Network | VPC network |
| Network | compute.googleapis.com/Subnetwork | Subnet |
| Network | compute.googleapis.com/Address | Reserved IP address |
| Network | dns.googleapis.com/ManagedZone | Cloud DNS zone |
| Storage and database | storage.googleapis.com/Bucket | Cloud Storage bucket |
| Storage and database | sqladmin.googleapis.com/Instance | Cloud SQL instance |
| Storage and database | bigquery.googleapis.com/Dataset | BigQuery dataset |
| Security and identity | iam.googleapis.com/ServiceAccount | Service account |
| Security and identity | iam.googleapis.com/ServiceAccountKey | Service account key |
| Security and identity | iam.googleapis.com/Role | Custom role |
| Security and identity | cloudkms.googleapis.com/CryptoKey | Cloud KMS key |
| Security and identity | secretmanager.googleapis.com/Secret | Secret Manager secret |
| Security and identity | orgpolicy.googleapis.com/Policy | Organization policy |
| Resource hierarchy | cloudresourcemanager.googleapis.com/Organization | Organization |
| Resource hierarchy | cloudresourcemanager.googleapis.com/Folder | Folder |
| Resource hierarchy | cloudresourcemanager.googleapis.com/Project | Project |
| Operations | serviceusage.googleapis.com/Service | Enabled API |
| Operations | logging.googleapis.com/LogSink | Log sink |
Multiple types can be specified with a regular expression. e.g. types="compute.googleapis.com/.*" (all Compute Engine), types="iam.googleapis.com/.*" (all IAM)
Examples
Example: Asset types in the organization
Situation: Find what kinds of resources exist in the organization and how many.
Expected result:
| asset_type | count |
|---|---|
| serviceusage.googleapis.com/Service | 52 |
| logging.googleapis.com/LogBucket | 8 |
| logging.googleapis.com/LogSink | 8 |
| iam.googleapis.com/ServiceAccountKey | 3 |
| cloudresourcemanager.googleapis.com/Project | 2 |
Interpretation: Number of resources by asset type. serviceusage.googleapis.com/Service is an API enabled in each project. Use the types option to see a specific type only.
Example: Service accounts and keys
Situation: Review service accounts and service account keys in the organization by project.
gcp-assets profile=gcp scope=organizations/123456789012 types="iam.googleapis.com/.*"
| fields project_id, asset_type, display_name, name, create_time
Expected result:
| project_id | asset_type | display_name | name | create_time |
|---|---|---|---|---|
| my-project-123456 | iam.googleapis.com/ServiceAccount | logpresso | //iam.googleapis.com/projects/my-project-123456/serviceAccounts/... | |
| my-project-123456 | iam.googleapis.com/ServiceAccountKey | projects/my-project-123456/serviceAccounts/.../keys/... | //iam.googleapis.com/projects/my-project-123456/serviceAccounts/.../keys/... | 2026-10-19 14:02:13+0900 |
Interpretation: Check for unused service accounts or old keys.
Example: Resources with a tag
Situation: Find resources that have a tag directly attached or inherited.
gcp-assets profile=gcp scope=organizations/123456789012 query="effectiveTagKeys:\"dev-team\""
| stats count by project_id, asset_type
Interpretation: The project the tag is attached to and all resources below it are returned. Use tagKeys: to find directly attached resources only.
Example: All projects in the organization including sub folders
Situation: scope of gcp-projects returns direct child projects only, so use this command to list all projects in the organization including sub folders.
gcp-assets profile=gcp scope=organizations/123456789012 types="cloudresourcemanager.googleapis.com/Project"
| fields project_id, display_name, folders, state, create_time
Interpretation: Folder numbers (folders) and state of each project are returned.