The reference agent's subject, cloud solution architecture, as an agent in the operating model agent's pattern: the Execution engine (from orchestration_engine) and one Workflow in app/solution_architecture, built for the settings and provider bundle by assembly.workflow_for. Copied from gcp_solution_architecture_agent at 8b397cd without its own engine: its role files, Skills, provider bundle, ADRs, vocabulary, scripts and evaluation datasets. The image takes the engine from a named build context and installs Terraform. It is called through the Orchestration engine, and its files are what the operating model agent digests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
130 lines
3.8 KiB
Markdown
130 lines
3.8 KiB
Markdown
# Eventarc
|
|
|
|
A trigger that delivers events to a Cloud Run service: one for messages on a Pub/Sub topic, one for objects finalised in a bucket.
|
|
|
|
- A trigger has its own service account. It needs `roles/eventarc.eventReceiver` on the project and `roles/run.invoker` on the service it calls.
|
|
- For a Pub/Sub trigger, name an existing topic under `transport.pubsub.topic`; left out, Eventarc creates a topic you do not manage.
|
|
- For a Cloud Storage trigger, `location` must be the bucket's location, and the Cloud Storage service agent needs `roles/pubsub.publisher` on the project before the trigger is created.
|
|
- `matching_criteria` attributes are exact. `type` is always present; a storage event also needs `bucket`.
|
|
- The destination service is named, with its `region`; `path` is optional.
|
|
- The service must not allow unauthenticated calls for this to be the only way in: grant `roles/run.invoker` to the trigger's service account only.
|
|
|
|
```hcl
|
|
variable "project_id" {
|
|
type = string
|
|
description = "Project to deploy into."
|
|
}
|
|
|
|
variable "region" {
|
|
type = string
|
|
description = "Region for regional resources."
|
|
}
|
|
|
|
variable "service_name" {
|
|
type = string
|
|
description = "Name of the Cloud Run service that receives the events."
|
|
}
|
|
|
|
variable "topic_id" {
|
|
type = string
|
|
description = "Id of the Pub/Sub topic whose messages are delivered."
|
|
}
|
|
|
|
variable "bucket_name" {
|
|
type = string
|
|
description = "Bucket whose new objects are delivered. It must be in var.region."
|
|
}
|
|
|
|
data "google_storage_project_service_account" "this" {
|
|
project = var.project_id
|
|
}
|
|
|
|
resource "google_service_account" "trigger" {
|
|
project = var.project_id
|
|
account_id = "eventarc-trigger"
|
|
display_name = "Eventarc trigger"
|
|
}
|
|
|
|
resource "google_project_iam_member" "trigger_receives_events" {
|
|
project = var.project_id
|
|
role = "roles/eventarc.eventReceiver"
|
|
member = "serviceAccount:${google_service_account.trigger.email}"
|
|
}
|
|
|
|
resource "google_cloud_run_v2_service_iam_member" "trigger_invokes_service" {
|
|
project = var.project_id
|
|
location = var.region
|
|
name = var.service_name
|
|
role = "roles/run.invoker"
|
|
member = "serviceAccount:${google_service_account.trigger.email}"
|
|
}
|
|
|
|
resource "google_project_iam_member" "storage_publishes_events" {
|
|
project = var.project_id
|
|
role = "roles/pubsub.publisher"
|
|
member = "serviceAccount:${data.google_storage_project_service_account.this.email_address}"
|
|
}
|
|
|
|
resource "google_eventarc_trigger" "on_message" {
|
|
project = var.project_id
|
|
name = "on-message"
|
|
location = var.region
|
|
service_account = google_service_account.trigger.email
|
|
|
|
matching_criteria {
|
|
attribute = "type"
|
|
value = "google.cloud.pubsub.topic.v1.messagePublished"
|
|
}
|
|
|
|
transport {
|
|
pubsub {
|
|
topic = var.topic_id
|
|
}
|
|
}
|
|
|
|
destination {
|
|
cloud_run_service {
|
|
service = var.service_name
|
|
region = var.region
|
|
path = "/events/message"
|
|
}
|
|
}
|
|
|
|
depends_on = [
|
|
google_project_iam_member.trigger_receives_events,
|
|
google_cloud_run_v2_service_iam_member.trigger_invokes_service,
|
|
]
|
|
}
|
|
|
|
resource "google_eventarc_trigger" "on_object" {
|
|
project = var.project_id
|
|
name = "on-object"
|
|
location = var.region
|
|
service_account = google_service_account.trigger.email
|
|
|
|
matching_criteria {
|
|
attribute = "type"
|
|
value = "google.cloud.storage.object.v1.finalized"
|
|
}
|
|
|
|
matching_criteria {
|
|
attribute = "bucket"
|
|
value = var.bucket_name
|
|
}
|
|
|
|
destination {
|
|
cloud_run_service {
|
|
service = var.service_name
|
|
region = var.region
|
|
path = "/events/object"
|
|
}
|
|
}
|
|
|
|
depends_on = [
|
|
google_project_iam_member.trigger_receives_events,
|
|
google_project_iam_member.storage_publishes_events,
|
|
google_cloud_run_v2_service_iam_member.trigger_invokes_service,
|
|
]
|
|
}
|
|
```
|