Melihat aset Anda

Dokumen ini menunjukkan cara melihat aset Anda menggunakan Inventaris Aset Cloud dan Google Cloud CLI di Cloud Shell.

Sebelum memulai

Untuk menyelesaikan petunjuk dalam dokumen ini, Anda harus mengaktifkan Cloud Asset Inventory API dan menyiapkan izin untuk akses ke Inventaris Aset Cloud dan 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

Peran yang diperlukan

Untuk mendapatkan izin yang Anda perlukan untuk menyelesaikan petunjuk ini, minta administrator untuk memberi Anda peran IAM berikut di organisasi, folder, atau project:

Untuk mengetahui informasi selengkapnya tentang pemberian peran, lihat Mengelola akses ke project, folder, dan organisasi.

Peran yang telah ditetapkan ini berisi izin yang diperlukan untuk menyelesaikan petunjuk ini. Untuk melihat izin yang benar-benar diperlukan, perluas bagian Izin yang diperlukan:

Izin yang diperlukan

Izin berikut diperlukan untuk menyelesaikan petunjuk ini:

  • Untuk mencantumkan metadata aset: cloudasset.assets.listResource
  • Untuk membuat instance VM Compute Engine:
    • compute.disks.create
    • compute.instances.create
    • compute.instances.delete
    • compute.instances.setServiceAccount
    • compute.projects.get
    • compute.subnetworks.use
    • compute.subnetworks.useExternalIp
    • compute.zoneOperations.get

Anda mungkin juga bisa mendapatkan izin ini dengan peran khusus atau peran bawaan lainnya.

Melihat aset Anda

Di project pilihan Anda, buat instance VM Compute Engine agar Anda dapat melihatnya di Inventaris Aset Cloud:

  1. Di konsol Google Cloud , buka halaman VM instances.

    Buka instance VM

  2. Klik Create instance.

  3. Masukkan nama untuk instance.

  4. Klik Create.

  5. Tunggu hingga instance selesai dibuat.

Cantumkan semua instance VM di project Anda:

  1. Di konsol Google Cloud , klik Activate Cloud Shell.

  2. Jalankan perintah berikut di Cloud Shell:

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

    Ganti PROJECT_ID dengan ID project yang asetnya ingin Anda cantumkan.

    Dalam contoh kode sebelumnya, jenis aset compute.googleapis.com/Instance digunakan untuk hanya mencantumkan instance VM Compute Engine. Untuk melihat semua jenis aset, lihat Jenis aset.

    Jenis konten resource juga telah ditetapkan. Hal ini menentukan bahwa metadata resource juga harus ditampilkan dalam respons. Jika tidak ada jenis konten yang ditetapkan, hanya informasi dasar tentang setiap aset yang akan ditampilkan, seperti nama aset, waktu terakhir diperbarui, dan project tempat aset tersebut berada.

Pembersihan

Agar akun Google Cloud Anda tidak dikenai biaya untuk resource yang digunakan pada halaman ini, ikuti langkah-langkah berikut.

  1. Di konsol Google Cloud , buka halaman VM instances.

    Buka instance VM

  2. Di baris yang sama dengan nama instance VM yang Anda buat, klik More actions.

  3. Klik Delete, lalu konfirmasi penghapusan.

Langkah berikutnya