# List service dependencies

> [!WARNING]
>
> **Preview
> --- Hierarchical service activation**
>
>
> This feature is
>
> subject to the "Pre-GA Offerings Terms" in the General Service Terms section of the
> [Service Specific
> Terms](https://docs.cloud.google.com/terms/service-terms#1).
>
> Pre-GA features are available "as is" and might have limited support.
>
> For more information, see the
> [launch stage descriptions](https://cloud.google.com/products/#product-launch-stages).

Viewing *service dependency groups* lets you identify services that are required
for services you enable to function. When you enable a service using
hierarchical service activation, its required dependencies are automatically added to the
`ConsumerPolicy` resource of the organization, folder, or project for which you
enable the service.

You can use the Google Cloud CLI to list service dependencies for projects,
folders, and organizations. For more information about hierarchical enablement,
see the
[overview](https://docs.cloud.google.com/service-usage/docs/hierarchical-service-activation/overview.md.txt).

## Before you begin

1. If you don't indicate the Google Cloud resource that you want to manage, the commands in this document default to the current project. For example, `gcloud beta services groups list-members bigquery.googleapis.com dependencies` lists the members for the current project.

   You can retrieve the current project ID:

   ```bash
   gcloud config list --format='text(core.project)'
   ```

<br />

### Required roles


To get the permissions that
you need to list service dependencies,

ask your administrator to grant you the
[Service Usage Viewer](https://docs.cloud.google.com/iam/docs/roles-permissions/serviceusage.md.txt#serviceusage.serviceUsageViewer) (`roles/serviceusage.serviceUsageViewer`) IAM role on your target resource.


For more information about granting roles, see [Manage access to projects, folders, and organizations](https://docs.cloud.google.com/iam/docs/granting-changing-revoking-access.md.txt).


This predefined role contains

the permissions required to list service dependencies. To see the exact permissions that are
required, expand the **Required permissions** section:


#### Required permissions

The following permissions are required to list service dependencies:

- List dependency group members: `serviceusage.groups.listMembers`
- List expanded dependency group members: `serviceusage.groups.listExpandedMembers`


You might also be able to get
these permissions
with [custom roles](https://docs.cloud.google.com/iam/docs/creating-custom-roles.md.txt) or
other [predefined roles](https://docs.cloud.google.com/iam/docs/roles-overview.md.txt#predefined).

## List dependency group members

You can list the direct members of a service dependency group for a project,
folder, or organization by using the
[`gcloud beta services groups list-members`](https://docs.cloud.google.com/sdk/gcloud/reference/beta/services/groups/list-members.md.txt)
command:

```bash
gcloud beta services groups list-members SERVICE GROUP \
    --RESOURCE_TYPE=RESOURCE_ID
```

Replace the following:

- `SERVICE`: the name of the service you want to
  list members for.

- `GROUP`: the name of the service dependency group
  you want to list members for. The primary supported group is `dependencies`.

- `RESOURCE_TYPE`: the type of the resource you want to
  list members for. Valid values are `project`, `folder`, and `organization`.
  You can omit this flag entirely to return results for the current project.

- `RESOURCE_ID`: the
  [project ID](https://docs.cloud.google.com/resource-manager/docs/creating-managing-projects.md.txt),
  [folder ID](https://docs.cloud.google.com/resource-manager/docs/creating-managing-folders.md.txt), or
  [organization ID](https://docs.cloud.google.com/resource-manager/docs/creating-managing-organization.md.txt#retrieving_your_organization_id),
  depending on the value you used for `RESOURCE_TYPE`.

You can use
[other flags](https://docs.cloud.google.com/sdk/gcloud/reference/beta/services/groups/list-members.md.txt)
to filter and limit the members listed.

## List expanded dependency group members

You can list the expanded members of a service dependency group for a project,
folder, or organization by using the
[`gcloud beta services groups list-expanded-members`](https://docs.cloud.google.com/sdk/gcloud/reference/beta/services/groups/list-expanded-members)
command.

This command returns a flattened list of all dependencies, including those in
nested groups, to provide a complete, combined list of all service dependencies.

```bash
gcloud beta services groups list-expanded-members SERVICE GROUP \
    --RESOURCE_TYPE=RESOURCE_ID
```

Replace the following:

- `SERVICE`: the name of the service you want to
  list members for.

- `GROUP`: the name of the service dependency group
  you want to list members for. The primary supported group is `dependencies`.

- `RESOURCE_TYPE`: the type of the resource you want to
  list members for. Valid values are `project`, `folder`, and `organization`.
  You can omit this flag entirely to return results for the current project.

- `RESOURCE_ID`: the
  [project ID](https://docs.cloud.google.com/resource-manager/docs/creating-managing-projects.md.txt),
  [folder ID](https://docs.cloud.google.com/resource-manager/docs/creating-managing-folders.md.txt), or
  [organization ID](https://docs.cloud.google.com/resource-manager/docs/creating-managing-organization.md.txt#retrieving_your_organization_id),
  depending on the value you used for `RESOURCE_TYPE`.

You can use
[other flags](https://docs.cloud.google.com/sdk/gcloud/reference/beta/services/groups/list-expanded-members)
to filter and limit the members listed.

## Examples

#### Listing direct dependency group members

- Listing direct dependencies of BigQuery service for the current project:

  ```bash
  gcloud beta services groups list-members bigquery.googleapis.com dependencies
  ```

  Output:

  ```yaml
  NAME: services/analyticshub.googleapis.com
  REASON: BigQuery depends on this group to allow users to exchange data and analytics assets.

  NAME: services/bigquery.googleapis.com
  REASON: The service representing BigQuery which owns this dependency group and depends on the other members of this group.

  NAME: services/bigqueryconnection.googleapis.com
  REASON: BigQuery depends on this group to allow users to manage connections to external data sources.

  NAME: services/bigquerydatapolicy.googleapis.com
  REASON: BigQuery depends on this group to allow users to manage their data policies.

  ...
  ```
- Attempting to list dependencies of API keys service without a corresponding service dependency group:

  ```bash
  gcloud beta services groups list-members apikeys.googleapis.com dependencies --project=test-project
  ```

  Output:

  ```yaml
  Listed 0 items.
  ```

#### Listing expanded dependency group members

- Listing expanded dependencies of BigQuery service for the current project:

  ```bash
  gcloud beta services groups list-expanded-members bigquery.googleapis.com dependencies
  ```

  Output:

  ```yaml
  services/analyticshub.googleapis.com
  services/bigquery.googleapis.com
  services/bigqueryconnection.googleapis.com
  services/bigquerydatapolicy.googleapis.com
  services/bigquerydatatransfer.googleapis.com
  services/bigquerymigration.googleapis.com
  services/bigqueryreservation.googleapis.com
  services/bigquerystorage.googleapis.com
  services/cloudresourcemanager.googleapis.com
  services/dataform.googleapis.com
  services/dataplex.googleapis.com
  ```

## What's next

- To enable and disable services, see [Manage service enablement](https://docs.cloud.google.com/service-usage/docs/hierarchical-service-activation/manage-enablement.md.txt).
- To manage policies, see [Manage consumer policies](https://docs.cloud.google.com/service-usage/docs/hierarchical-service-activation/manage-consumer-policies.md.txt).