Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Halaman ini menunjukkan cara mengelola unit penyewa untuk
layanan Anda. Unit keanggotaan adalah resource ringan
yang merepresentasikan hubungan antara
konsumen layanan dan
layanan terkelola. Setiap konsumen layanan hanya dapat memiliki satu unit penyewa aktif untuk layanan terkelola. Ini adalah fitur
yang disediakan oleh Service Infrastructure.
Nama resource unit penyewa memiliki format berikut:
services/{your service name}/projects/{consumer project number}/tenancyUnits/{id}
ID unit sewa dibuat secara otomatis saat Anda membuatnya. Anda juga dapat
memberikan ID saat memanggil
metode services.tenancyUnits.create. Jika Anda memberikan ID, ID tersebut harus unik secara global dalam cakupan layanan terkelola Anda di semua konsumen layanan.
Contoh di halaman ini menggunakan panggilan langsung ke REST API Service Consumer Management.
Untuk penggunaan produksi, sebaiknya gunakan library klien yang disediakan Google untuk kegunaan dan keandalan yang lebih baik.
Sebelum memulai
Service Consumer Management API ditujukan untuk digunakan dengan
layanan terkelola dan project
produsen layanan. Anda harus sudah memiliki
project Google Cloud dan layanan terkelola (seperti layanan yang dibuat menggunakan
Cloud Endpoints) dalam project tersebut.
Untuk menggunakan unit penyewa, Service Consumer Management API perlu membuat project tenant di organisasi produsen layanan Anda. Pastikan Anda memiliki kuota yang cukup untuk jumlah project tenant yang diperlukan bagi konsumen layanan Anda.
Setiap project tenant yang dibuat di unit tenancy juga harus berada di
folder yang Anda tentukan
sebagai bagian dari konfigurasi project tenant. Oleh karena itu, Anda memerlukan
Organisasi untuk menggunakan
unit penyewa.
Autentikasi
Select the tabs for how you plan to access the API:
gcloud
Menginstal Google Cloud CLI.
Setelah penginstalan,
lakukan inisialisasi Google Cloud CLI dengan menjalankan perintah berikut:
Untuk menggunakan library klien di lingkungan pengembangan lokal, instal dan lakukan inisialisasi
gcloud CLI, lalu siapkan Kredensial Default Aplikasi dengan kredensial pengguna
Anda.
Unit tenant dan project tenant di dalamnya biasanya dibuat saat
resource di layanan Anda sendiri dibuat yang bergantung pada
resource Google Cloud tambahan yang akan disediakan untuk konsumen.
POST https://serviceconsumermanagement.googleapis.com/v1/services/service.example.com/projects/12345678901/tenancyUnits
Di sini, 'projects/12345678901' mewakili konsumen layanan, dan
service.example.com adalah nama layanan Anda.
Struktur data yang ditampilkan memiliki nama unit keanggotaan, dengan ID unik yang dihasilkan yang dapat digunakan untuk mengaksesnya. Dalam contoh ini, nama yang dihasilkan adalah
services/your-service.example.com/projects/12345678901/tenancyUnits/absdef.
Menambahkan project tenant
Sekarang Anda dapat menambahkan project untuk pengguna. Untuk menambahkan project tenant baru ke
unit keanggotaan yang dibuat pada langkah sebelumnya, gunakan
metode services.tenancyUnits.addProject:
POST https://serviceconsumermanagement.googleapis.com/v1/services/your-service.example.com/projects/12345678901/tenancyUnits/absdef:addProject
Nilai tag adalah ID yang Anda berikan untuk project dalam unit
penyewa: ID ini dapat berupa apa saja yang Anda inginkan (di sini adalah tag1), seperti wilayah, jaringan
konsumen, atau hanya ID string.
Panggilan ini menampilkan operasi yang berjalan lama yang dapat Anda kueri untuk mengetahui apakah pembuatan project berhasil.
Jika Anda perlu menerapkan konfigurasi yang berbeda, misalnya untuk menambahkan layanan terkelola baru, Anda dapat memanggil metode
services.tenancyUnits.applyProjectConfig.
Menelusuri unit tenancy Anda
Menemukan unit tenancy untuk konsumen layanan
Untuk menemukan unit penyewa bagi konsumen layanan tertentu, gunakan
metode services.tenancyUnits.list,
dengan menentukan nomor project konsumen layanannya:
GET https://serviceconsumermanagement.googleapis.com/v1/services/your-service.example.com/projects/12345678901/tenancyUnits
Menelusuri unit tenancy
Anda dapat menggunakan
metode services.search
untuk menelusuri unit tenancy yang ditentukan
untuk layanan Anda. Misalnya, kueri berikut akan menampilkan semua unit yang
berisi project dengan tag 'tag1':
GET https://serviceconsumermanagement.googleapis.com/v1/services/your-service.example.com:search?query=tenant_resources.tag=tag1
Membersihkan unit tenancy
Saat konsumen layanan berhenti menggunakan layanan Anda, Anda perlu menghapus unit penyewaannya untuk membebaskan resource dan memastikan data pengguna dihapus.
Menghapus project tenant
Anda harus menghapus semua project tenant sebelum menghapus unit tenant yang sesuai. Anda harus menggunakan metode
services.tenancyUnits.removeProject
untuk menghapus project tenant dan semua resource di dalamnya:
POST https://serviceconsumermanagement.googleapis.com/v1/services/your-service.example.com/projects/12345678901/tenancyUnits/absdef:removeProject
Menghapus unit tenancy
Setelah menghapus semua project tenant dalam unit keanggotaan, atau semuanya
berada dalam status DELETED, Anda dapat menghapus unit keanggotaan menggunakan
metode services.tenancyUnits.delete:
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-08-11 UTC."],[],[],null,["# Managing Tenancy Units\n\nThis page shows you how to manage [tenancy units](/service-infrastructure/docs/glossary#tenancy) for\nyour service. A [tenancy unit](/service-infrastructure/docs/glossary#tenancy) is a lightweight resource\nthat represents the relationship between a\n[service consumer](/service-infrastructure/docs/glossary#consumer) and a\n[managed service](/service-infrastructure/docs/glossary#managed). Each service consumer can have\nonly one active tenancy unit for a managed service. This is a feature\nprovided by Service Infrastructure.\n\nThe resource name of a tenancy unit has the following format: \n\n services/{your service name}/projects/{consumer project number}/tenancyUnits/{id}\n\nThe ID of a tenancy unit is auto-generated when you create it. You can also\nprovide an ID when you call the\n[`services.tenancyUnits.create`](/service-infrastructure/docs/service-consumer-management/reference/rest/v1/services.tenancyUnits/create)\nmethod. If you provide an ID, it must be globally unique within the scope of\nyour managed service across all service consumers.\n\nThe examples on this page use direct calls to the Service Consumer Management\n[REST API](/service-infrastructure/docs/service-consumer-management/reference/rest).\nFor production usage, we recommend you use Google-provided client libraries\nfor better usability and reliability.\n\nBefore you begin\n----------------\n\n- The Service Consumer Management API is intended for use with [managed services](/service-infrastructure/docs/glossary#managed) and [service producer](/service-infrastructure/docs/glossary#producer) projects. You'll need to already have a Google Cloud project and a managed service (such as a service created using [Cloud Endpoints](/endpoints/docs)) in that project.\n- To use tenancy units, the Service Consumer Management API needs to create tenant projects in your service producer organization. Make sure that you have enough quota for the necessary number of tenant projects for your service's consumers.\n- To create and delete tenancy units, follow the initial setup instructions in [Getting Started with the Service Consumer Management API](/service-infrastructure/docs/service-consumer-management/getting-started).\n- Each tenant project created in a tenancy unit must also be in a [folder](/resource-manager/docs/creating-managing-folders) that you specify as part of the tenant project configuration. Because of this, you need an [Organization](/resource-manager/docs/creating-managing-organization) to use tenancy units.\n\nAuthentication\n--------------\n\nSelect the tabs for how you plan to access the API: \n\n### gcloud\n\n\n[Install](/sdk/docs/install) the Google Cloud CLI.\n\nAfter installation,\n[initialize](/sdk/docs/initializing) the Google Cloud CLI by running the following command:\n\n```bash\ngcloud init\n```\n\n\nIf you're using an external identity provider (IdP), you must first\n[sign in to the gcloud CLI with your federated identity](/iam/docs/workforce-log-in-gcloud).\n\n### Client libraries\n\n\nTo use client libraries in a local development environment, install and initialize the\ngcloud CLI, and then set up Application Default Credentials with your user\ncredentials.\n\n1. [Install](/sdk/docs/install) the Google Cloud CLI.\n2. If you're using an external identity provider (IdP), you must first [sign in to the gcloud CLI with your federated identity](/iam/docs/workforce-log-in-gcloud).\n3. If you're using a local shell, then create local authentication credentials for your user account: \n\n```bash\ngcloud auth application-default login\n```\n4. You don't need to do this if you're using Cloud Shell.\n5. If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have [signed in to the gcloud CLI with your federated identity](/iam/docs/workforce-log-in-gcloud).\n\n\nFor more information, see\n[Set up ADC for a local development environment](/docs/authentication/set-up-adc-local-dev-environment)\nin the Google Cloud authentication documentation.\n\n### REST\n\n\nTo use the REST API in a local development environment, you use the credentials you provide to\nthe gcloud CLI.\n\n1. [Install](/sdk/docs/install) the Google Cloud CLI.\n2. If you're using an external identity provider (IdP), you must first [sign in to the gcloud CLI with your federated identity](/iam/docs/workforce-log-in-gcloud).\n\n\nFor more information, see\n[Authenticate for using REST](/docs/authentication/rest)\nin the Google Cloud authentication documentation.\n\n\nFor information about setting up authentication for a production\nenvironment, see\n[Set up Application Default Credentials for code running on\nGoogle Cloud](/docs/authentication/set-up-adc-attached-service-account)\nin the Google Cloud authentication documentation.\n\n\u003cbr /\u003e\n\nCreating a tenancy unit\n-----------------------\n\nTenancy units and the tenant projects in them are normally created when\nresources in your own service are created that depend on additional\nGoogle Cloud resources to be provisioned for the consumers.\n\nYou create a tenancy unit using the\n[`services.tenancyUnits.create` method](/service-infrastructure/docs/service-consumer-management/reference/rest/v1/services.tenancyUnits/create): \n\n POST https://serviceconsumermanagement.googleapis.com/v1/services/service.example.com/projects/12345678901/tenancyUnits\n\nHere, 'projects/12345678901' represents the service consumer, and\n`service.example.com` is the name of your service.\n\nThe returned data structure has the name of the tenancy unit, with a generated\nunique id that can be used to access it. In this example, the generated name is\n`services/your-service.example.com/projects/12345678901/tenancyUnits/absdef`.\n\nAdding a tenant project\n-----------------------\n\nYou can now add a project for the user. To add a new tenant project to the\ntenancy unit created in the previous step, use the\n[`services.tenancyUnits.addProject` method](/service-infrastructure/docs/service-consumer-management/reference/rest/v1/services.tenancyUnits/addProject): \n\n POST https://serviceconsumermanagement.googleapis.com/v1/services/your-service.example.com/projects/12345678901/tenancyUnits/absdef:addProject\n\nwith the following data: \n\n {\"tag\":\"tag1\", \"project_config\":{\"folder\":\"folders/9876543210\", \"tenant_project_policy\":{\"policy_bindings\":{\"role\":\"roles/owner\", \"members\":\"user:bob@example.com\"}}, \"billing_config\":{\"billing_account\":\"billingAccounts/123456-472F22-28F9AA\"}}}\n\nThe `tag` value is an identifier you provide for the project within the tenancy\nunit: this can be anything you like (here it's `tag1`), such as a region, a\nconsumer network, or just a string ID.\n\nThis call returns a long running operation that you can query to find if the\nproject creation was successful.\n\nIf you need to apply a different configuration, for example to add new managed\nservices, you can call the\n[`services.tenancyUnits.applyProjectConfig`](/service-infrastructure/docs/service-consumer-management/reference/rest/v1/services.tenancyUnits/applyProjectConfig)\nmethod.\n\nSearching your tenancy units\n----------------------------\n\n### Find a tenancy unit for a service consumer\n\nTo find a tenancy unit for a particular service consumer, use the\n[`services.tenancyUnits.list` method](/service-infrastructure/docs/service-consumer-management/reference/rest/v1/services.tenancyUnits/list),\nspecifying their service consumer project number: \n\n GET https://serviceconsumermanagement.googleapis.com/v1/services/your-service.example.com/projects/12345678901/tenancyUnits\n\n### Search tenancy units\n\nYou can use the\n[`services.search` method](/service-infrastructure/docs/service-consumer-management/reference/rest/v1/services/search)\nto search for tenancy units defined\nfor your service. For example, the following query will return all units that\ncontain a project with the tag 'tag1': \n\n GET https://serviceconsumermanagement.googleapis.com/v1/services/your-service.example.com:search?query=tenant_resources.tag=tag1\n\nCleaning up tenancy units\n-------------------------\n\nWhen a service consumer stops using your service, you need to remove its\ntenancy unit to free up resources and ensure the user data is deleted.\n\n### Remove tenant projects\n\nYou need to delete all tenant projects before you delete the corresponding\ntenancy unit. You should use the\n[`services.tenancyUnits.removeProject`](/service-infrastructure/docs/service-consumer-management/reference/rest/v1/services.tenancyUnits/removeProject)\nmethod to delete a tenant project and all resources in it: \n\n POST https://serviceconsumermanagement.googleapis.com/v1/services/your-service.example.com/projects/12345678901/tenancyUnits/absdef:removeProject\n\n### Delete a tenancy unit\n\nAfter you have deleted all tenant projects in a tenancy unit, or all of them\nare in the `DELETED` state, you can delete the tenancy unit using the\n[`services.tenancyUnits.delete` method](/service-infrastructure/docs/service-consumer-management/reference/rest/v1/services.tenancyUnits/delete): \n\n DELETE https://serviceconsumermanagement.googleapis.com/v1/services/your-service.example.com/projects/12345678901/tenancyUnits/absdef"]]