列出服务依赖项
借助分层服务启用,您可以管理通过 Google Cloud 资源层次结构继承的服务启用状态。如需了解详情,请参阅概览。
许多 Google Cloud 服务都需要其他服务才能正常运行。使用分层服务激活功能启用服务时,系统会自动将该服务所需的相关依赖项添加到 ConsumerPolicy 中。服务依赖项组包含这些依赖的服务,您可以列出这些服务,以便更好地了解和管理它们。
本文档介绍了如何使用 Google Cloud CLI 列出项目、文件夹和组织的服务依赖项。
准备工作
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
Install the Google Cloud CLI.
-
如果您使用的是外部身份提供方 (IdP),则必须先使用联合身份登录 gcloud CLI。
-
如需初始化 gcloud CLI,请运行以下命令:
gcloud init -
Create or select a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Create a Google Cloud project:
gcloud projects create PROJECT_ID
Replace
PROJECT_IDwith a name for the Google Cloud project you are creating. -
Select the Google Cloud project that you created:
gcloud config set project PROJECT_ID
Replace
PROJECT_IDwith your Google Cloud project name.
-
如果您要使用现有项目来完成本指南,请验证您是否拥有完成本指南所需的权限。如果您创建了新项目,则您已拥有所需的权限。
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Service Usage API:
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.gcloud services enable serviceusage.googleapis.com
-
Install the Google Cloud CLI.
-
如果您使用的是外部身份提供方 (IdP),则必须先使用联合身份登录 gcloud CLI。
-
如需初始化 gcloud CLI,请运行以下命令:
gcloud init -
Create or select a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Create a Google Cloud project:
gcloud projects create PROJECT_ID
Replace
PROJECT_IDwith a name for the Google Cloud project you are creating. -
Select the Google Cloud project that you created:
gcloud config set project PROJECT_ID
Replace
PROJECT_IDwith your Google Cloud project name.
-
如果您要使用现有项目来完成本指南,请验证您是否拥有完成本指南所需的权限。如果您创建了新项目,则您已拥有所需的权限。
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Service Usage API:
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.gcloud services enable serviceusage.googleapis.com
- 如果您未指明要管理的 Google Cloud 资源,本文档中的命令将默认针对当前项目执行。例如,
gcloud beta services groups list-members bigquery.googleapis.com dependencies列出了当前项目的成员。您可以检索当前项目 ID:
gcloud config list --format='text(core.project)'
-
列出依赖项组成员:
serviceusage.groups.listMembers -
列出展开的依赖项组成员:
serviceusage.groups.listExpandedMembers SERVICE:您要列出成员的服务的名称。GROUP:您要列出其成员的服务依赖项组的名称。主要支持的群组是dependencies。PROJECT_ID:您的Google Cloud 项目 ID。 或者,省略该标志以默认使用当前项目。SERVICE:您要列出成员的服务的名称。GROUP:您要列出其成员的服务依赖项组的名称。主要支持的群组为dependencies。FOLDER_ID:您的Google Cloud 文件夹 ID。SERVICE:您要列出成员的服务的名称。GROUP:您要列出其成员的服务依赖项组的名称。主要支持的群组是dependencies。ORGANIZATION_ID:您的Google Cloud 组织资源 ID。SERVICE:您要列出成员的服务的名称。GROUP:您要列出其成员的服务依赖项组的名称。主要支持的群组是dependencies。PROJECT_ID:您的Google Cloud 项目 ID。 或者,省略该标志以默认使用当前项目。SERVICE:您要列出成员的服务的名称。GROUP:您要列出其成员的服务依赖项组的名称。主要支持的群组是dependencies。FOLDER_ID:您的Google Cloud 文件夹 ID。SERVICE:您要列出成员的服务的名称。GROUP:您要列出其成员的服务依赖项组的名称。主要支持的群组为dependencies。ORGANIZATION_ID:您的Google Cloud 组织资源 ID。- 列出当前项目的 BigQuery 服务的直接依赖项:
gcloud beta services groups list-members bigquery.googleapis.com dependencies
输出:
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. ...
- 尝试列出 API 密钥服务的依赖项,但没有相应的服务依赖项组:
gcloud beta services groups list-members apikeys.googleapis.com dependencies --project=test-project
输出:
Listed 0 items. - 列出当前项目的 BigQuery 服务的扩展依赖项:
gcloud beta services groups list-expanded-members bigquery.googleapis.com dependencies
输出:
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
所需的角色
如需获得列出服务依赖项所需的权限,请让您的管理员为您授予目标资源的 Service Usage Viewer (roles/serviceusage.serviceUsageViewer) IAM 角色。
如需详细了解如何授予角色,请参阅管理对项目、文件夹和组织的访问权限。
此预定义角色包含列出服务依赖项所需的权限。如需查看所需的确切权限,请展开所需权限部分:
所需权限
如需列出服务依赖项,您需要具有以下权限:
列出依赖项组成员
您可以使用 gcloud beta services groups list-members 命令列出项目、文件夹或组织的服务依赖关系组的直接成员。
项目
gcloud beta services groups list-members SERVICE GROUP \
--project=PROJECT_ID
替换以下内容:
文件夹
gcloud beta services groups list-members SERVICE GROUP \
--folder=FOLDER_ID
替换以下内容:
组织
gcloud beta services groups list-members SERVICE GROUP \
--organization=ORGANIZATION_ID
替换以下内容:
您可以使用其他标志来过滤和限制列出的成员。
列出展开的依赖关系组成员
您可以使用 gcloud beta services groups list-expanded-members 命令列出项目、文件夹或组织的依赖服务组的展开成员。
此命令会返回所有依赖项(包括嵌套组中的依赖项)的扁平化列表,以提供所有服务依赖项的完整合并列表。
项目
gcloud beta services groups list-expanded-members SERVICE GROUP \
--project=PROJECT_ID
替换以下内容:
文件夹
gcloud beta services groups list-expanded-members SERVICE GROUP \
--folder=FOLDER_ID
替换以下内容:
组织
gcloud beta services groups list-expanded-members SERVICE GROUP \
--organization=ORGANIZATION_ID
替换以下内容:
您可以使用其他标志来过滤和限制列出的成员。