アセットを表示する

このドキュメントでは、Cloud Shell で Cloud Asset Inventory と Google Cloud CLI を使用してアセットを表示する方法について説明します。

始める前に

このドキュメントの手順を完了するには、Cloud Asset Inventory API を有効にして、Cloud Asset Inventory と Compute Engine へのアクセス権限を設定する必要があります。

  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 role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  3. このガイドで既存のプロジェクトを使用する場合は、このガイドを完了するために必要な権限があることを確認します。新しいプロジェクトを作成した場合は、必要な権限がすでに付与されています。

  4. Enable the Cloud Asset Inventory 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

  5. 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 role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  6. このガイドで既存のプロジェクトを使用する場合は、このガイドを完了するために必要な権限があることを確認します。新しいプロジェクトを作成した場合は、必要な権限がすでに付与されています。

  7. Enable the Cloud Asset Inventory 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

  8. 必要なロール

    これらの手順を完了するために必要な権限を取得するには、組織、フォルダ、またはプロジェクトに対する次の IAM ロールを付与するよう管理者に依頼します。

    ロールの付与については、プロジェクト、フォルダ、組織へのアクセス権の管理をご覧ください。

    これらの事前定義ロールには、これらの手順を完了するために必要な権限が含まれています。必要とされる正確な権限については、「必要な権限」セクションを開いてご確認ください。

    必要な権限

    この手順を完了するには、次の権限が必要です。

    • アセット メタデータを一覧表示するには: cloudasset.assets.listResource
    • Compute Engine VM インスタンスを作成するには:
      • compute.disks.create
      • compute.instances.create
      • compute.instances.delete
      • compute.instances.setServiceAccount
      • compute.projects.get
      • compute.subnetworks.use
      • compute.subnetworks.useExternalIp
      • compute.zoneOperations.get

    カスタムロールや他の事前定義ロールを使用して、これらの権限を取得することもできます。

    アセットを表示する

    任意のプロジェクトで、Cloud Asset Inventory に表示されるように Compute Engine VM インスタンスを作成します。

    1. Google Cloud コンソールで、[VM インスタンス] ページに移動します。

      [VM インスタンス] に移動

    2. [インスタンスを作成] をクリックします。

    3. インスタンスの名前を入力します。

    4. [作成] をクリックします。

    5. インスタンスが作成されるまで待ちます。

    プロジェクト内のすべての VM インスタンスを一覧表示します。

    1. Google Cloud コンソールで、 Cloud Shell をアクティブにするをクリックします。

    2. Cloud Shell で、次のコマンドを実行します。

      gcloud asset list \
          --project=PROJECT_ID \
          --asset-types=compute.googleapis.com/Instance \
          --content-type=resource
      

      PROJECT_ID は、アセットを一覧表示するプロジェクトの ID に置き換えます。

      前のコードサンプルでは、アセットタイプ compute.googleapis.com/Instance を使用して、Compute Engine VM インスタンスのみを一覧表示しています。すべてのアセットタイプを表示するには、アセットタイプをご覧ください。

      コンテンツ タイプ resource も設定されています。これにより、レスポンスで返される resource メタデータも指定されます。コンテンツ タイプが設定されていない場合は、アセット名、最終更新日時、アセットが属するプロジェクトなど、各アセットに関する基本情報のみが返されます。

    クリーンアップ

    このページで使用したリソースについて、 Google Cloud アカウントに課金されないようにするには、次の手順を実施します。

    1. Google Cloud コンソールで、[VM インスタンス] ページに移動します。

      [VM インスタンス] に移動

    2. 作成した VM インスタンスの名前と同じ行で、 [その他の操作] をクリックします。

    3. [削除] をクリックして、削除を確定します。

    次のステップ