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

Flo*_*aus 4 google-cloud-storage google-cloud-platform terraform event-arc

我想为 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
}
Run Code Online (Sandbox Code Playgroud)

当我运行此示例时,出现以下错误:

Error: Error creating Trigger: googleapi: Error 400: The request was invalid: The request was invalid: missing required attribute "bucket" in trigger.event_filters
Run Code Online (Sandbox Code Playgroud)

Flo*_*aus 8

阅读文档并没有帮助,但在多次阅读使用 Terraform 创建 Eventarc 触发器 博客文章后,我找到了答案。可以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
}
Run Code Online (Sandbox Code Playgroud)