Service Management API を使ってみる

このページでは、Service Management API と連携するように開発環境を設定する方法について説明します。Service Management API を使用する最も簡単な方法(Google Cloud コンソール ウェブ UI を使用する以外の方法)で、ほとんどの運用上のユースケースで推奨される方法は、gcloud コマンドライン インターフェースを使用することです。Service Management API に対してプログラミングする必要がある場合は、用意されているクライアント ライブラリの 1 つを使用することをおすすめします。API を試してみるには、以下の代替セットアップ手順に沿って curl コマンドを使用します。これにより、完全なアプリケーション開発環境をセットアップしなくても API を試すことができます。

gcloud を使用したセットアップ

  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. In the Google Cloud console, on the project selector page, select or create 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 (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  3. Enable the Service Management 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.

    Enable the API

  4. Install the Google Cloud CLI.

  5. 外部 ID プロバイダ(IdP)を使用している場合は、まず連携 ID を使用して gcloud CLI にログインする必要があります。

  6. gcloud CLI を初期化するには、次のコマンドを実行します。

    gcloud init
  7. In the Google Cloud console, on the project selector page, select or create 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 (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  8. Enable the Service Management 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.

    Enable the API

  9. Install the Google Cloud CLI.

  10. 外部 ID プロバイダ(IdP)を使用している場合は、まず連携 ID を使用して gcloud CLI にログインする必要があります。

  11. gcloud CLI を初期化するには、次のコマンドを実行します。

    gcloud init
  12. API を直接呼び出すためのセットアップ

    このセクションでは、curl コマンドを使用して Service Management API を試すためのローカル環境を設定するために必要な基本的な手順について説明します。これは、Service Management API に対してプログラミングする必要のあるデベロッパーを対象としています。

    初期設定

    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. 外部 ID プロバイダ(IdP)を使用している場合は、まず連携 ID を使用して 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 (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. Enable the Service Management 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 servicemanagement.googleapis.com
    7. Grant roles to your user account. Run the following command once for each of the following IAM roles: roles/servicemanagement.admin

      gcloud projects add-iam-policy-binding PROJECT_ID --member="user:USER_IDENTIFIER" --role=ROLE

      Replace the following:

      • PROJECT_ID: Your project ID.
      • USER_IDENTIFIER: The identifier for your user account. For example, myemail@example.com.
      • ROLE: The IAM role that you grant to your user account.
    8. Install the Google Cloud CLI.

    9. 外部 ID プロバイダ(IdP)を使用している場合は、まず連携 ID を使用して gcloud CLI にログインする必要があります。

    10. gcloud CLI を初期化するには、次のコマンドを実行します。

      gcloud init
    11. 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 (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.

    12. Enable the Service Management 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 servicemanagement.googleapis.com
    13. Grant roles to your user account. Run the following command once for each of the following IAM roles: roles/servicemanagement.admin

      gcloud projects add-iam-policy-binding PROJECT_ID --member="user:USER_IDENTIFIER" --role=ROLE

      Replace the following:

      • PROJECT_ID: Your project ID.
      • USER_IDENTIFIER: The identifier for your user account. For example, myemail@example.com.
      • ROLE: The IAM role that you grant to your user account.
    14. curl によるテスト

      1. Google REST API の呼び出しに便利なシェル エイリアスを定義します。

        $ alias gcurl='curl -H "Authorization: Bearer $(gcloud auth print-access-token)" -H "Content-Type: application/json"'
        
      2. 一般公開されているサービスの一覧表示を試行します。

        $ gcurl https://servicemanagement.googleapis.com/v1/services
        

        サービスのリストが表示されれば設定は成功です。

      次のステップ

      Cloud Endpoints を使用しておらず、マネージド サービスを作成する場合は、次の手順を行います。

      1. サービスの作成と削除の手順に沿ってマネージド サービスを作成します。これにより、トップレベルのマネージド サービス リソースが作成されます。
      2. サービス構成の管理の手順に沿って、サービスによって使用される機能を記述したサービス構成を送信します。

      3. サービス構成のロールアウトの手順に沿ってサービス構成をロールアウトします。