アセットを表示する

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

始める前に

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

  1. 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

  2. If you're using an existing project for this guide, verify that you have the permissions required to complete this guide. If you created a new project, then you already have the required permissions.

  3. Enable the Cloud Asset Inventory API, if it is not already enabled.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.

    Enable the API

必要なロール

これらの手順を完了するために必要な権限を取得するには、組織、フォルダ、またはプロジェクトに対する次の 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. [削除] をクリックして、削除を確定します。

次のステップ