You can retrieve up to 35 days of create, update, and delete history for your assets in Google Cloud projects or organizations. Assets that haven't changed in the past 35 days report their latest status.
Before you begin
Enable the Cloud Asset Inventory API in the project you're running Cloud Asset Inventory commands from.
Make sure your account has the correct role to call the Cloud Asset Inventory API. For individual permissions for each call type, see Permissions.
Limitations
You can only retrieve asset history at the organization and project level. Folders aren't supported.
Get your asset histories
Console
To get the history of your assets stored in Google Cloud, complete the following steps.
-
Go to the Asset Inventory page in the Google Cloud console.
- Change to the project, folder, or organization you want to search.
- Click the Resource tab.
- Click a resource in the results panel.
- Click the Change history tab.
- Select a Start time and End time for the report.
- Use the Select a record to compare list boxes to show a diff between the records for your selected dates.
After performing a search, the resources matching the query are listed in the Results table. Double-click your query to edit it, or use the Filter results pane to retrict the search results by specific criteria.
To view the query as a Google Cloud CLI command, click View query.
To export the results, click Download CSV.
gcloud
gcloud asset get-history \ --SCOPE \ --asset-names=ASSET_NAME_1,ASSET_NAME_2,... \ --content-type=CONTENT_TYPE \ --relationship-types=RELATIONSHIP_TYPE_1,RELATIONSHIP_TYPE_2,... \ --start-time="START_TIME" \ --end-time="END_TIME"
Provide the following values:
-
SCOPE
: Use one of the following values:-
project=PROJECT_ID
, wherePROJECT_ID
is the ID of the project that has the asset you want to retrieve. -
organization=ORGANIZATION_ID
, whereORGANIZATION_ID
is the ID of the organization that has the asset you want to retrieve.How to find the ID of a Google Cloud organization
Google Cloud console
To find the ID of a Google Cloud organization, complete the following steps:
-
Go to the Google Cloud console.
- Click the switcher list box in the menu bar.
- Select your organization from the list box.
- Click the All tab. The organization ID is shown next to the organization name.
gcloud CLI
You can retrieve the ID of a Google Cloud organization with the following command:
gcloud organizations describe ORGANIZATION_NAME --format="value(name.segment(1))"
-
-
ASSET_NAME_#
: A comma-separated list of asset full names.CONTENT_TYPE
: The content type of the metadata you want to retrieve. When--content-type
isn't specified, only basic information is returned, such as asset names, the last time the assets were updated, and what projects, folders, and organizations they belong to.-
RELATIONSHIP_TYPE_#
: Optional. Requires access to the Security Command Center Premium or Enterprise tier, or [Gemini Cloud Assist](/products/gemini/cloud-assist). A comma-separated list of asset relationship types you want to retrieve. You must setCONTENT_TYPE
toRELATIONSHIP
for this to work. -
START_TIME
: The beginning of the time range, in gcloud topic datetime format. The value must be no more than 35 days in the past. -
END_TIME
: Optional. The finishing point of the time range, in gcloud topic datetime format. The value must be no more than 35 days in the past. When--end-time
isn't specified, it's set to the current time.
See the gcloud CLI reference for all options.
Example
Run the following command to get the resource
history metadata of the
my-instance
Compute Engine instance in the my-project
project
between January 30, 2024 and February 5, 2024. The instance has the following properties:
- Instance name:
my-instance
- Project:
my-project
- Location:
us-central1-a
gcloud asset get-history \ --project=my-project \ --asset-names=//compute.googleapis.com/projects/my-project/zones/us-central1-a/instances/my-instance \ --content-type=resource \ --start-time="2024-01-30" \ --end-time="2024-02-05"
Example response
--- asset: ancestors: - projects/000000000000 - folders/000000000000 - organizations/000000000000 assetType: compute.googleapis.com/Instance name: //compute.googleapis.com/projects/my-project/zones/us-central1-a/instances/my-instance resource: data: LATEST_ASSET_METADATA discoveryDocumentUri: https://www.googleapis.com/discovery/v1/apis/compute/v1/rest discoveryName: Instance location: us-central1-a parent: //cloudresourcemanager.googleapis.com/projects/000000000000 version: v1 updateTime: '2024-02-05T16:00:25.259186Z' window: endTime: '2024-02-05T16:00:25.259186Z' startTime: '2024-02-03T16:00:28.854779Z' --- asset: ancestors: - projects/000000000000 - folders/000000000000 - organizations/000000000000 assetType: compute.googleapis.com/Instance name: //compute.googleapis.com/projects/my-project/zones/us-central1-a/instances/my-instance resource: data: EARLIEST_ASSET_METADATA discoveryDocumentUri: https://www.googleapis.com/discovery/v1/apis/compute/v1/rest discoveryName: Instance location: us-central1-a parent: //cloudresourcemanager.googleapis.com/projects/000000000000 version: v1 updateTime: '2024-02-03T16:00:28.854779Z' window: endTime: '2024-02-03T16:00:28.854779Z' startTime: '2024-01-30T08:00:22.930462Z'
REST
HTTP method and URL:
POST https://cloudasset.googleapis.com/v1/SCOPE_PATH:batchGetAssetsHistory
Request JSON body:
{ "assetNames": [ "ASSET_NAME_1", "ASSET_NAME_2", "..." ], "contentType": "CONTENT_TYPE", "relationshipTypes": [ "RELATIONSHIP_TYPE_1", "RELATIONSHIP_TYPE_2", "..." ], "readTimeWindow": { "startTime": "START_TIME", "endTime": "END_TIME" } }
Provide the following values:
-
SCOPE_PATH
: Use one of the following values:The allowed values are:
-
projects/PROJECT_ID
, wherePROJECT_ID
is the ID of the project that has the asset you want to retrieve. -
projects/PROJECT_NUMBER
, wherePROJECT_NUMBER
is the number of the project that has the asset you want to retrieve.How to find a Google Cloud project number
Google Cloud console
To find a Google Cloud project number, complete the following steps:
-
Go to the Welcome page in the Google Cloud console.
- Click the switcher list box in the menu bar.
-
Select your organization from the list box, and then search for your project name. The project name, project number, and project ID are shown near the Welcome heading.
Up to 4,000 resources are displayed. If you don't see the project you're looking for, go to the Manage resources page and filter the list using the name of that project.
gcloud CLI
You can retrieve a Google Cloud project number with the following command:
gcloud projects describe PROJECT_ID --format="value(projectNumber)"
-
-
organizations/ORGANIZATION_ID
, whereORGANIZATION_ID
is the ID of the organization that has the asset you want to retrieve.How to find the ID of a Google Cloud organization
Google Cloud console
To find the ID of a Google Cloud organization, complete the following steps:
-
Go to the Google Cloud console.
- Click the switcher list box in the menu bar.
- Select your organization from the list box.
- Click the All tab. The organization ID is shown next to the organization name.
gcloud CLI
You can retrieve the ID of a Google Cloud organization with the following command:
gcloud organizations describe ORGANIZATION_NAME --format="value(name.segment(1))"
-
-
ASSET_NAME_#
: An array of asset full names.CONTENT_TYPE
: The content type of the metadata you want to retrieve. WhencontentType
isn't specified, only basic information is returned, such as asset names, the last time the assets were updated, and what projects, folders, and organizations they belong to.-
RELATIONSHIP_TYPE_#
: Optional. Requires access to the Security Command Center Premium or Enterprise tier, or [Gemini Cloud Assist](/products/gemini/cloud-assist). A comma-separated list of asset relationship types you want to retrieve. You must setCONTENT_TYPE
toRELATIONSHIP
for this to work. -
START_TIME
: The beginning of the time range, in RFC 3339 format. The value must be no more than 35 days in the past. -
END_TIME
: Optional. The finishing point of the time range, in RFC 3339 format. The value must be no more than 35 days in the past. WhenendTime
isn't specified, it's set to the current time.
See the REST reference for all options.
Command examples
Run one of the following commands to get the resource
history of the
my-instance
Compute Engine instance in the my-project
project
between January 30, 2024 and February 5, 2024. The instance has the following properties:
- Instance name:
my-instance
- Project:
my-project
- Location:
us-central1-a
curl (Linux, macOS, or Cloud Shell)
curl -X POST \ -H "X-HTTP-Method-Override: GET" \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json; charset=utf-8" \ -d '{ "assetNames": ["//compute.googleapis.com/projects/my-project/zones/us-central1-a/instances/my-instance"], "contentType": "RESOURCE", "readTimeWindow": { "startTime": "2024-01-30T00:00:00Z", "endTime": "2024-02-05T00:00:00Z" } }' \ https://cloudasset.googleapis.com/v1/projects/my-project:batchGetAssetsHistory
PowerShell (Windows)
$cred = gcloud auth print-access-token $headers = @{ "X-HTTP-Method-Override" = "GET"; "Authorization" = "Bearer $cred" } $body = @" { "assetNames": ["//compute.googleapis.com/projects/my-project/zones/us-central1-a/instances/my-instance"], "contentType": "RESOURCE", "readTimeWindow": { "startTime": "2024-01-30T00:00:00Z", "endTime": "2024-02-05T00:00:00Z" } } "@ Invoke-WebRequest ` -Method POST ` -Headers $headers ` -ContentType: "application/json; charset=utf-8" ` -Body $body ` -Uri "https://cloudasset.googleapis.com/v1/projects/my-project:batchGetAssetsHistory" | Select-Object -Expand Content
Example response
{ "assets": [ { "window": { "startTime": "2024-02-03T16:00:28.854779Z", "endTime": "2024-02-05T16:00:25.259186Z" }, "asset": { "name": "//compute.googleapis.com/projects/my-project/zones/us-central1-a/instances/my-instance", "assetType": "compute.googleapis.com/Instance", "resource": { "version": "v1", "discoveryDocumentUri": "https://www.googleapis.com/discovery/v1/apis/compute/v1/rest", "discoveryName": "Instance", "parent": "//cloudresourcemanager.googleapis.com/projects/000000000000", "data": { LATEST_ASSET_METADATA }, "location": "us-central1-a" }, "ancestors": [ "projects/000000000000", "folders/000000000000", "organizations/000000000000" ], "updateTime": "2024-02-05T16:00:25.259186Z" } }, { "window": { "startTime": "2024-01-30T08:00:22.930462Z", "endTime": "2024-02-03T16:00:28.854779Z" }, "asset": { "name": "//compute.googleapis.com/projects/my-project/zones/us-central1-a/instances/my-instance", "assetType": "compute.googleapis.com/Instance", "resource": { "version": "v1", "discoveryDocumentUri": "https://www.googleapis.com/discovery/v1/apis/compute/v1/rest", "discoveryName": "Instance", "parent": "//cloudresourcemanager.googleapis.com/projects/000000000000", "data": { EARLIEST_ASSET_METADATA }, "location": "us-central1-a" }, "ancestors": [ "projects/000000000000", "folders/000000000000", "organizations/000000000000" ], "updateTime": "2024-02-03T16:00:28.854779Z" } } ] }
C#
To learn how to install and use the client library for Cloud Asset Inventory, see Cloud Asset Inventory client libraries.
To authenticate to Cloud Asset Inventory, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Go
To learn how to install and use the client library for Cloud Asset Inventory, see Cloud Asset Inventory client libraries.
To authenticate to Cloud Asset Inventory, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Java
To learn how to install and use the client library for Cloud Asset Inventory, see Cloud Asset Inventory client libraries.
To authenticate to Cloud Asset Inventory, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Node.js
To learn how to install and use the client library for Cloud Asset Inventory, see Cloud Asset Inventory client libraries.
To authenticate to Cloud Asset Inventory, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
PHP
To learn how to install and use the client library for Cloud Asset Inventory, see Cloud Asset Inventory client libraries.
To authenticate to Cloud Asset Inventory, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Python
To learn how to install and use the client library for Cloud Asset Inventory, see Cloud Asset Inventory client libraries.
To authenticate to Cloud Asset Inventory, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Ruby
To learn how to install and use the client library for Cloud Asset Inventory, see Cloud Asset Inventory client libraries.
To authenticate to Cloud Asset Inventory, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.