如何在 terraform 中为 GCS 创建 eventarc 触发器?

How to create an eventarc trigger in terraform for GCS?

我想为 GCS 对象创建创建一个 eventarc 触发器。根据 Eventarc 文档,这应该使用直接 GCS 触发器。我可以这样创建它,但我不知道将存储桶名称放在哪里:

resource "google_eventarc_trigger" "upload" {
  name     = "upload"
  location = "europe-west1"
  matching_criteria {
    attribute = "type"
    value     = "google.cloud.storage.object.v1.finalized"
  }
  destination {
    workflow = google_workflows_workflow.process_file.id
  }
  service_account = google_service_account.workflow.email
}

当我运行这个例子时,我得到以下错误:

Error: Error creating Trigger: googleapi: Error 400: The request was invalid: The request was invalid: missing required attribute "bucket" in trigger.event_filters

阅读 documentation 没有帮助,但在阅读 Creating Eventarc triggers with Terraform 之后 博客 post 多次我找到了答案。 bucket 可以像这样作为 matching_criteria 的另一个块提供:

resource "google_eventarc_trigger" "upload" {
  name     = "upload"
  location = "europe-west1"
  matching_criteria {
    attribute = "type"
    value     = "google.cloud.storage.object.v1.finalized"
  }
  matching_criteria {
    attribute = "bucket"
    value     = google_storage_bucket.uploads.name
  }
  destination {
    workflow = google_workflows_workflow.process_file.id
  }
  service_account = google_service_account.workflow.email
}