Merutekan peristiwa Certificate Manager ke Alur Kerja

Pemicu Eventarc menyatakan minat Anda pada peristiwa atau rangkaian peristiwa tertentu. Anda dapat mengonfigurasi pemilihan rute peristiwa dengan menentukan filter untuk pemicu, termasuk sumber peristiwa, dan alur kerja target.

Peristiwa dikirim dalam format CloudEvents melalui permintaan HTTP. Layanan Alur kerja mengonversi peristiwa menjadi objek JSON (mengikuti spesifikasi CloudEvents) dan meneruskan peristiwa ke 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 pemilihan rute 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 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 berlaku, aktifkan API yang terkait dengan peristiwa langsung. Misalnya, untuk peristiwa Certificate Manager , aktifkan APICertificate Manager .

  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, di 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 Alur Kerja.

      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 berlaku, aktifkan API yang terkait dengan peristiwa langsung. Misalnya, untuk peristiwa Certificate Manager , aktifkan certificatemanager.googleapis.com.

  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. Buat akun layanan:

      gcloud iam service-accounts create SERVICE_ACCOUNT_NAME

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

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

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 Pemicu Eventarc.

    Buka Pemicu

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

    Ini adalah ID pemicu dan harus diawali dengan huruf. Nama dapat berisi maksimal 63 huruf kecil, angka, atau tanda hubung.

  4. Untuk Jenis pemicu, pilih Sumber Google.
  5. Dalam daftar Penyedia peristiwa, pilih Certificate Manager.

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

  6. Di daftar Jenis peristiwa, dari peristiwa Langsung, pilih jenis peristiwa.
  7. Untuk menentukan encoding payload peristiwa, di daftar Jenis konten data peristiwa, pilih application/json atau application/protobuf.

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

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

    Untuk informasi selengkapnya, lihat Lokasi Eventarc.

  9. Jika berlaku untuk penyedia peristiwa, klik Tambahkan 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 Attribute value 1, bergantung pada operator yang Anda pilih, ketik nilai yang tepat atau terapkan pola jalur.
    4. Jika ada filter atribut lainnya yang berlaku, klik Tambahkan filter dan tentukan nilai yang sesuai.
  10. Pilih Service account yang akan memanggil layanan atau alur kerja Anda.

    Atau, Anda dapat membuat akun layanan baru.

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

  11. Dalam daftar Tujuan peristiwa, pilih Workflows.
  12. Pilih alur kerja.

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

    Untuk mengetahui informasi selengkapnya, lihat Membuat pemicu untuk Alur Kerja.

  13. Secara opsional, untuk menambahkan label, Anda dapat mengklik Tambahkan label. Label adalah pasangan nilai kunci yang membantu Anda mengatur resourceGoogle Cloud . Untuk 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 pemicu lama. Untuk informasi selengkapnya, lihat Mengelola pemicu.

  1. Klik Buat.

gcloud

Anda dapat membuat pemicu dengan menjalankan perintah gcloud eventarc triggers create bersama dengan 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 mencocokkan peristiwa untuk ID certificate yang dimulai dengan my-certificate-.