Merutekan peristiwa Certificate Manager ke Alur Kerja

Pemicu Eventarc mendeklarasikan minat Anda pada peristiwa atau kumpulan peristiwa tertentu. Anda dapat mengonfigurasi perutean peristiwa dengan menentukan filter untuk pemicu, termasuk sumber peristiwa, dan alur kerja target.

Peristiwa dikirim dalam format CloudEvents melalui permintaan HTTP. Layanan Workflows mengonversi peristiwa menjadi objek JSON (dengan mengikuti spesifikasi CloudEvents) dan meneruskan peristiwa ke dalam eksekusi alur kerja sebagai argumen runtime alur kerja. Pastikan ukuran peristiwa tidak melebihi 512 KB. Peristiwa yang lebih besar dari ukuran argumen Workflows maksimum tidak akan memicu eksekusi alur kerja.

Petunjuk ini menunjukkan cara mengonfigurasi perutean peristiwa sehingga eksekusi alur kerja Anda dipicu sebagai respons terhadap peristiwa Certificate Manager langsung. Untuk mengetahui detail selengkapnya, lihat daftar peristiwa langsung yang didukung.

Bersiap untuk membuat pemicu

Sebelum membuat pemicu Eventarc untuk alur kerja target, selesaikan tugas-tugas berikut.

Konsol

  1. Di konsol Google Cloud, pada halaman pemilih project, pilih atau buat Google Cloud project.

    Buka pemilih project

  2. Aktifkan Eventarc, Eventarc Publishing, Workflows, dan Workflow Executions API.

    Mengaktifkan API

  3. Jika memungkinkan, aktifkan API yang terkait dengan peristiwa langsung. Misalnya, untuk Certificate Manager peristiwa, aktifkan Certificate Manager API.

  4. Jika Anda belum memilikinya, buat akun layanan yang dikelola pengguna, lalu berikan peran dan izin yang diperlukan agar Eventarc dapat mengelola peristiwa untuk alur kerja target.

    1. Di Konsol Google Cloud, buka halaman Akun layanan.

      Buka Akun Layanan

    2. Pilih project Anda.

    3. Di kolom Nama akun layanan, masukkan nama. Konsol Google Cloud akan mengisi kolom ID akun layanan berdasarkan nama ini.

      Di kolom Deskripsi akun layanan, masukkan sebuah deskripsi. Contoh, Service account for event trigger.

    4. Klik Buat dan lanjutkan.

    5. Untuk memberikan akses yang sesuai, pada daftar Select a role, pilih peran Identity and Access Management (IAM) yang diperlukan untuk diberikan ke akun layanan Anda. Untuk mengetahui informasi selengkapnya, lihat Peran dan izin untuk target Workflows.

      Untuk peran tambahan, klik Tambahkan peran lain, lalu tambahkan setiap peran tambahan.

    6. Klik Lanjutkan.

    7. Untuk menyelesaikan pembuatan akun, klik Selesai.

gcloud

  1. In the Google Cloud console, activate Cloud Shell.

    Activate Cloud Shell

    At the bottom of the Google Cloud console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.

  2. Aktifkan Eventarc, Eventarc Publishing, Workflows, dan Workflow Executions API:

    gcloud services enable eventarc.googleapis.com \
        eventarcpublishing.googleapis.com \
        workflows.googleapis.com \
        workflowexecutions.googleapis.com

  3. Jika memungkinkan, aktifkan API yang terkait dengan peristiwa langsung. Misalnya, untuk Certificate Manager peristiwa, aktifkan certificatemanager.googleapis.com.

  4. Jika Anda belum memilikinya, buat akun layanan yang dikelola pengguna, lalu berikan peran dan izin yang diperlukan sehingga Eventarc dapat mengelola peristiwa untuk alur kerja target.

    1. Buat akun layanan:

      gcloud iam service-accounts create SERVICE_ACCOUNT_NAME

      Ganti SERVICE_ACCOUNT_NAME dengan nama akun layanan. Panjangnya harus antara 6 hingga 30 karakter, serta dapat berisi karakter alfanumerik huruf kecil dan tanda hubung. Setelah membuat akun layanan, Anda tidak dapat mengubah namanya.

    2. Memberikan peran atau izin Identity and Access Management (IAM) yang diperlukan. Untuk mengetahui informasi selengkapnya, lihat Peran dan izin untuk target Workflows.

Buat pemicu

Anda dapat membuat pemicu Eventarc dengan alur kerja yang di-deploy sebagai penerima peristiwa menggunakan Google Cloud CLI (gcloud atau Terraform), atau melalui Konsol Google Cloud.

Konsol

  1. Di Konsol Google Cloud, buka halaman Triggers Eventarc.

    Buka Pemicu

  2. Klik Create trigger.
  3. Ketik Nama pemicu.

    Ini adalah ID pemicu dan harus diawali dengan huruf. Kolom ini dapat berisi hingga 63 huruf kecil, angka, atau tanda hubung.

  4. Untuk Jenis pemicu, pilih Sumber Google.
  5. Dalam daftar Event provider, pilih Certificate Manager.

    Perhatikan bahwa nama penyedia peristiwa yang digunakan dalam Google Cloud dokumentasi terkait mungkin tidak memiliki awalan Cloud atau Google Cloud. Misalnya, di konsol, Memorystore for Redis disebut sebagai Google Cloud Memorystore for Redis.

  6. Dalam daftar Event type, dari peristiwa Direct, pilih jenis peristiwa.
  7. Untuk menentukan encoding payload peristiwa, dalam daftar Jenis konten data peristiwa, pilih application/json atau application/protobuf.

    Perhatikan bahwa payload peristiwa yang diformat dalam JSON lebih besar dari yang diformat dalam Protobuf. Hal ini dapat memengaruhi keandalan, bergantung pada tujuan peristiwa Anda dan batasnya pada ukuran peristiwa. Untuk mengetahui informasi selengkapnya, lihat Masalah umum.

  8. Dalam daftar Region, pilih global (Global).

    Untuk mengetahui informasi selengkapnya, lihat Lokasi Eventarc.

  9. Jika berlaku untuk penyedia peristiwa, klik Add filter, lalu tentukan hal berikut:
    1. Di kolom Atribut 1, bergantung pada peristiwa langsung yang Anda pilih, pilih ID resource yang dapat berfungsi sebagai filter peristiwa.
    2. Pilih operator:
    3. Di kolom Nilai atribut 1, bergantung pada operator yang Anda pilih, ketik nilai yang tepat atau terapkan pola jalur.
    4. Jika ada lebih banyak filter atribut yang berlaku, klik Add filter, lalu tentukan nilai yang sesuai.
  10. Pilih Service account yang akan memanggil layanan atau alur kerja Anda.

    Atau, Anda dapat membuat akun layanan baru.

    Tindakan ini menentukan email akun layanan Identity and Access Management (IAM) yang terkait dengan pemicu dan tempat Anda sebelumnya memberikan peran tertentu yang diperlukan oleh Eventarc.

  11. Dalam daftar Event destination, pilih Workflows.
  12. Pilih alur kerja.

    Ini adalah nama alur kerja yang akan menerima peristiwa. Peristiwa untuk eksekusi alur kerja ditransformasi dan diteruskan ke alur kerja sebagai argumen runtime.

    Untuk mengetahui informasi selengkapnya, lihat Membuat pemicu untuk Workflows.

  13. Jika ingin, untuk menambahkan label, Anda dapat mengklik Tambahkan label. Label adalah key-value pair yang membantu Anda mengatur Google Cloud resource. Untuk mengetahui informasi selengkapnya, lihat Apa yang dimaksud dengan label?
  14. Klik Buat.
  15. Setelah pemicu dibuat, filter sumber peristiwa tidak dapat diubah. Sebagai gantinya, buat pemicu baru dan hapus yang lama. Untuk mengetahui informasi selengkapnya, lihat Mengelola pemicu.

  1. Klik Buat.

gcloud

Anda dapat membuat pemicu dengan menjalankan perintah gcloud eventarc triggers create beserta flag wajib dan opsional.

gcloud eventarc triggers create TRIGGER \
  --location=global \
  --destination-workflow=DESTINATION_WORKFLOW  \
  --destination-workflow-location=DESTINATION_WORKFLOW_LOCATION \
  --event-filters="type=EVENT_FILTER_TYPE" \
  --event-filters="COLLECTION_ID=RESOURCE_ID" \
  --event-filters-path-pattern="COLLECTION_ID=PATH_PATTERN" \
  --event-data-content-type="EVENT_DATA_CONTENT_TYPE" \
  --service-account="MY_SERVICE_ACCOUNT@PROJECT_ID.iam.gserviceaccount.com"

Replace the following:

  • TRIGGER: the ID of the trigger or a fully qualified identifier.
  • DESTINATION_WORKFLOW: the ID of the deployed workflow that receives the events from the trigger. The workflow can be in any of the Workflows supported locations and does not need to be in the same location as the trigger. However, the workflow must be in the same project as the trigger.
  • DESTINATION_WORKFLOW_LOCATION (optional): the location in which the destination workflow is deployed. If not specified, it is assumed that the workflow is in the same location as the trigger.
  • EVENT_FILTER_TYPE: the identifier of the event. An event is generated when an API call for the method succeeds. For long-running operations, the event is only generated at the end of the operation, and only if the action is performed successfully. For a list of supported event types, see Google event types supported by Eventarc.
  • COLLECTION_ID (optional): the resource component that can act as an event filter, and is one of the following:
    • certificate
    • certificateissuanceconfig
    • certificatemap
    • certificatemapentry
    • dnsauthorization
  • RESOURCE_ID: the identifier of the resource used as the filtering value for the associated collection. For more information, see Resource ID.
  • PATH_PATTERN: the path pattern to apply when filtering for the resource
  • EVENT_DATA_CONTENT_TYPE: (optional) the encoding of the event payload. This can be application/json or application/protobuf. The default encoding is application/json.

    Note that an event payload formatted in JSON is larger than one formatted in Protobuf. This might impact reliability depending on your event destination and its limits on event size. For more information, see Known issues.

  • SERVICE_ACCOUNT_NAME: the name of the IAM service account you created to which you granted specific roles required by Workflows.
  • PROJECT_ID: your Google Cloud project ID

Notes:

  • The --location flag must be global. For more information, see Eventarc locations.
  • The --event-filters="type=EVENT_FILTER_TYPE" flag is required. If no other event filter is set, events for all resources are matched.
  • EVENT_FILTER_TYPE cannot be changed after creation. To change EVENT_FILTER_TYPE, create a new trigger and delete the old one.
  • Each trigger can have multiple event filters, comma delimited in one --event-filters=[ATTRIBUTE=VALUE,...] flag, or you can repeat the flag to add more filters. Only events that match all the filters are sent to the destination. Wildcards and regular expressions are not supported; however, when using the --event-filters-path-pattern flag, you can define a resource path pattern.
  • The --service-account flag is used to specify the Identity and Access Management (IAM) service account email associated with the trigger.

Example:

gcloud eventarc triggers create helloworld-trigger \
  --location=global \
  --destination-workflow=my-workflow \
  --destination-workflow-location=us-central1 \
  --event-filters="type=google.cloud.certificatemanager.certificate.v1.updated" \
  --event-filters-path-pattern="certificate=my-certificate-*" \
  --service-account="${SERVICE_ACCOUNT_NAME}@${PROJECT_ID}.iam.gserviceaccount.com"

Perintah ini membuat pemicu yang disebut helloworld-trigger untuk peristiwa yang diidentifikasi sebagai google.cloud.certificatemanager.certificate.v1.updated dan cocok dengan peristiwa untuk ID certificate yang dimulai dengan my-certificate-.