アセットを表示する
このドキュメントでは、Cloud Asset Inventory と Cloud Shell の Google Cloud CLI を使用してアセットを表示する方法について説明します。
始める前に
このドキュメントの手順を完了するには、Cloud Asset Inventory API を有効にし、Cloud Asset Inventory と Compute Engine へのアクセス権を設定する必要があります。
-
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 theresourcemanager.projects.createpermission. Learn how to grant roles.
-
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.
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.enablepermission. 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.
必要なロール
これらの手順を完了するために必要な権限を取得するには、組織、フォルダ、またはプロジェクトに対する次の IAM ロールを付与するよう管理者に依頼します。
-
アセットのメタデータを表示する: クラウド アセット閲覧者(
roles/cloudasset.viewer) -
Compute Engine VM インスタンスを作成して削除するには:
- Compute インスタンス管理者(v1)(
roles/compute.instanceAdmin.v1) - サービス アカウント ユーザー(
roles/iam.serviceAccountUser)
- Compute インスタンス管理者(v1)(
ロールの付与については、プロジェクト、フォルダ、組織へのアクセス権の管理をご覧ください。
これらの事前定義ロールには、この手順を完了するために必要な権限が含まれています。必要とされる正確な権限については、「必要な権限」セクションを開いてご確認ください。
必要な権限
これらの手順を完了するには、次の権限が必要です。
-
アセットのメタデータを一覧表示するには:
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 インスタンスを作成します。
Google Cloud コンソールで、[VM インスタンス] ページに移動します。
[インスタンスを作成] をクリックします。
インスタンスの名前を入力します。
[作成] をクリックします。
インスタンスが作成されるまで待ちます。
プロジェクト内のすべての VM インスタンスを一覧表示します。
Google Cloud コンソールで、 Cloud Shell をアクティブにするをクリックします。
Cloud Shell で、次のコマンドを実行します。
gcloud asset list \ --project=PROJECT_ID \ --asset-types=compute.googleapis.com/Instance \ --content-type=resourcePROJECT_IDは、アセットを一覧表示するプロジェクトの ID に置き換えます。上記のコードサンプルでは、
compute.googleapis.com/Instanceのアセットタイプを使用して、Compute Engine VM インスタンスのみを一覧表示しています。すべてのアセットタイプを表示するには、アセットタイプをご覧ください。コンテンツ タイプ
resourceも設定されています。これにより、レスポンスで返されるresourceメタデータも指定されます。コンテンツ タイプが設定されていない場合は、アセット名、最終更新日時、アセットが含まれるプロジェクトなど、各アセットに関する基本情報のみが返されます。
クリーンアップ
このページで使用したリソースについて、 Google Cloud アカウントに課金されないようにするには、次の手順を実施します。
Google Cloud コンソールで、[VM インスタンス] ページに移動します。
作成した VM インスタンスの名前と同じ行で、 [その他の操作] をクリックします。
[削除] をクリックして、削除を確定します。
次のステップ
- アセットの表示に関連するその他のオプションについては、アセットの一覧表示をご覧ください。