列出服務依附元件

階層式服務啟用功能可讓您管理透過 Google Cloud 資源階層繼承的服務啟用狀態。詳情請參閱總覽

許多 Google Cloud 服務需要其他服務才能運作。使用階層式服務啟用功能啟用服務時,系統會自動將必要依附元件新增至 ConsumerPolicy服務依附元件群組包含這些依附元件服務,您可以列出這些服務,以便進一步瞭解及管理。

本文說明如何使用 Google Cloud CLI 列出專案、資料夾和機構的服務依附元件。

事前準備

  1. 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.
  2. Install the Google Cloud CLI.

  3. 若您採用的是外部識別資訊提供者 (IdP),請先使用聯合身分登入 gcloud CLI

  4. 執行下列指令,初始化 gcloud CLI:

    gcloud init
  5. 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 the resourcemanager.projects.create permission. Learn how to grant roles.
    • Create a Google Cloud project:

      gcloud projects create PROJECT_ID

      Replace PROJECT_ID with 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_ID with your Google Cloud project name.

  6. 如要使用現有專案進行本指南中的操作,請確認您具有完成本指南所需的權限。如果您建立新專案,則已具備必要權限。

  7. Verify that billing is enabled for your Google Cloud project.

  8. 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 the serviceusage.services.enable permission. Learn how to grant roles.

    gcloud services enable serviceusage.googleapis.com
  9. Install the Google Cloud CLI.

  10. 若您採用的是外部識別資訊提供者 (IdP),請先使用聯合身分登入 gcloud CLI

  11. 執行下列指令,初始化 gcloud CLI:

    gcloud init
  12. 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 the resourcemanager.projects.create permission. Learn how to grant roles.
    • Create a Google Cloud project:

      gcloud projects create PROJECT_ID

      Replace PROJECT_ID with 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_ID with your Google Cloud project name.

  13. 如要使用現有專案進行本指南中的操作,請確認您具有完成本指南所需的權限。如果您建立新專案,則已具備必要權限。

  14. Verify that billing is enabled for your Google Cloud project.

  15. 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 the serviceusage.services.enable permission. Learn how to grant roles.

    gcloud services enable serviceusage.googleapis.com
  16. 如果您未指出要管理的 Google Cloud 資源,本文中的指令會預設為目前的專案。舉例來說,gcloud beta services groups list-members bigquery.googleapis.com dependencies 會列出目前專案的成員。

    您可以擷取目前的專案 ID:

    gcloud config list --format='text(core.project)'
  17. 必要的角色

    如要取得列出服務依附元件所需的權限,請要求管理員授予您目標資源的服務使用情形檢視者 (roles/serviceusage.serviceUsageViewer) IAM 角色。如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和組織的存取權」。

    這個預先定義的角色具備列出服務依附元件所需的權限。如要查看確切的必要權限,請展開「Required permissions」(必要權限) 部分:

    所需權限

    如要列出服務依附元件,您必須具備下列權限:

    • 列出依附元件群組成員: serviceusage.groups.listMembers
    • 列出展開的依附元件群組成員: serviceusage.groups.listExpandedMembers

    您或許還可透過自訂角色或其他預先定義的角色取得這些權限。

    列出依附元件群組成員

    您可以使用 gcloud beta services groups list-members 指令,列出專案、資料夾或機構的服務依附元件群組直接成員。

    專案

    gcloud beta services groups list-members  SERVICE GROUP \
        --project=PROJECT_ID
    

    更改下列內容:

    • SERVICE:您要列出成員的服務名稱。
    • GROUP:要列出成員的服務依附元件群組名稱。主要支援的群組為 dependencies
    • PROJECT_ID:您的 Google Cloud 專案 ID。 或者,省略這個旗標,預設為目前的專案。

    資料夾

    gcloud beta services groups list-members  SERVICE  GROUP \
        --folder=FOLDER_ID
    

    更改下列內容:

    • SERVICE:您要列出成員的服務名稱。
    • GROUP:要列出成員的服務依附元件群組名稱。主要支援的群組為 dependencies
    • FOLDER_ID:您的Google Cloud 資料夾 ID

    機構

    gcloud beta services groups list-members  SERVICE  GROUP \
        --organization=ORGANIZATION_ID
    

    更改下列內容:

    • SERVICE:您要列出成員的服務名稱。
    • GROUP:要列出成員的服務依附元件群組名稱。主要支援的群組為 dependencies
    • ORGANIZATION_ID:您的Google Cloud 機構資源 ID

    您可以使用其他標記來篩選及限制列出的成員。

    列出展開的依附元件群組成員

    您可以使用 gcloud beta services groups list-expanded-members 指令,列出專案、資料夾或機構的服務依附元件群組擴展成員。

    這項指令會傳回所有依附元件的扁平化清單,包括巢狀群組中的依附元件,提供所有服務依附元件的完整合併清單。

    專案

    gcloud beta services groups list-expanded-members SERVICE GROUP \
        --project=PROJECT_ID
    

    更改下列內容:

    • SERVICE:您要列出成員的服務名稱。
    • GROUP:要列出成員的服務依附元件群組名稱。主要支援的群組為 dependencies
    • PROJECT_ID:您的Google Cloud 專案 ID。或者,省略這個旗標,預設為目前的專案。

    資料夾

    gcloud beta services groups list-expanded-members SERVICE  GROUP \
        --folder=FOLDER_ID
    

    更改下列內容:

    • SERVICE:您要列出成員的服務名稱。
    • GROUP:要列出成員的服務依附元件群組名稱。主要支援的群組為 dependencies
    • FOLDER_ID:您的Google Cloud 資料夾 ID

    機構

    gcloud beta services groups list-expanded-members SERVICE  GROUP \
        --organization=ORGANIZATION_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

    後續步驟