Group assets

Stay organized with collections Save and categorize content based on your preferences.

Demonstrates how to group assets by attributes

Code sample


static ImmutableList<GroupResult> groupAssets(OrganizationName organizationName) {
  try (SecurityCenterClient client = SecurityCenterClient.create()) {
    // Start setting up a request for to group all assets by type in an organization.
    // OrganizationName organizationName = OrganizationName.of("123234324");
    GroupAssetsRequest.Builder request =

    // Call the API.
    GroupAssetsPagedResponse response = client.groupAssets(;

    // This creates one list for all assets.  If your organization has a large number of assets
    // this can cause out of memory issues.  You can process them batches by returning
    // the Iterable returned response.iterateAll() directly.
    ImmutableList<GroupResult> results = ImmutableList.copyOf(response.iterateAll());
    System.out.println("All assets:");
    return results;
  } catch (IOException e) {
    throw new RuntimeException("Couldn't create client.", e);


from import securitycenter

client = securitycenter.SecurityCenterClient()

# organization_id is the numeric ID of the organization.
# organization_id = "1234567777"
org_name = "organizations/{org_id}".format(org_id=organization_id)

group_by_type = "security_center_properties.resource_type"

result_iterator = client.group_assets(
    request={"parent": org_name, "group_by": group_by_type}
for i, result in enumerate(result_iterator):
    print((i + 1), result)

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.