How to create an eventarc trigger in terraform for GCS?

1.7k views Asked by At

I would like to create an eventarc trigger for GCS object creation. According to the Eventarc documentation, this should use the direct GCS trigger. I can create it like this, but I don't know where to put the bucket name:

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
}

When I run this example, I get the following error:

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

There are 1 answers

0
Florian Feldhaus On BEST ANSWER

Reading the documentation didn't help, but after reading the Creating Eventarc triggers with Terraform blog post multiple times I found the answer. The bucket can be provided as another block of matching_criteria like this:

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
}