アセットを表示する
このドキュメントでは、Cloud Shell で Cloud Asset Inventory と Google Cloud CLI を使用してアセットを表示する方法について説明します。
始める前に
Cloud Asset Inventory を使用する前に、Cloud Asset Inventory API を有効にして権限を設定する必要があります。
- 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.
-
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 theresourcemanager.projects.create
permission. Learn how to grant roles.
-
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 theserviceusage.services.enable
permission. Learn how to grant roles. -
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 theresourcemanager.projects.create
permission. Learn how to grant roles.
-
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 theserviceusage.services.enable
permission. Learn how to grant roles. -
ユーザーに次のロールを付与します。
Cloud Asset オーナー(
roles/cloudasset.owner
)。 Google Cloud コンソールで、[VM インスタンス] ページに移動します。
[インスタンスを作成] をクリックします。
インスタンスの名前を入力します。
[作成] をクリックします。
Google Cloud コンソールで、
Cloud Shell をアクティブにするをクリックします。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 コンソールで、[VM インスタンス] ページに移動します。
作成した VM インスタンスの名前と同じ行で、
[その他の操作] をクリックします。[削除] をクリックして、削除を確定します。
- アセットの表示に関するその他のオプションについては、アセットの一覧表示をご覧ください。
アセットを表示する
任意のプロジェクトで、Cloud Asset Inventory に表示されるように Compute Engine VM インスタンスを作成します。
プロジェクト内のすべての VM インスタンスを一覧表示します。
クリーンアップ
このページで使用したリソースについて、 Google Cloud アカウントに課金されないようにするには、次の手順を実施します。