|
| 1 | +resource "google_firestore_database" "database" { |
| 2 | + project = "{{index $.TestEnvVars "project_id"}}" |
| 3 | + name = "{{index $.Vars "database_id"}}" |
| 4 | + location_id = "us-central1" |
| 5 | + type = "FIRESTORE_NATIVE" |
| 6 | + |
| 7 | + delete_protection_state = "DELETE_PROTECTION_DISABLED" |
| 8 | + deletion_policy = "DELETE" |
| 9 | +} |
| 10 | + |
| 11 | +resource "google_eventarc_trigger" "{{$.PrimaryResourceId}}" { |
| 12 | + name = "{{index $.Vars "trigger_name"}}" |
| 13 | + location = "us-central1" |
| 14 | + matching_criteria { |
| 15 | + attribute = "type" |
| 16 | + value = "google.cloud.firestore.document.v1.written" |
| 17 | + } |
| 18 | + matching_criteria { |
| 19 | + attribute = "database" |
| 20 | + value = google_firestore_database.database.name |
| 21 | + } |
| 22 | + destination { |
| 23 | + cloud_run_service { |
| 24 | + service = google_cloud_run_service.default.name |
| 25 | + region = "us-central1" |
| 26 | + } |
| 27 | + } |
| 28 | + event_data_content_type = "application/protobuf" |
| 29 | + service_account = google_service_account.trigger_service_account.email |
| 30 | + depends_on = [google_project_iam_member.event_receiver] |
| 31 | +} |
| 32 | + |
| 33 | +resource "google_service_account" "trigger_service_account" { |
| 34 | + account_id = "{{index $.Vars "service_account_id"}}" |
| 35 | +} |
| 36 | + |
| 37 | +resource "google_project_iam_member" "event_receiver" { |
| 38 | + project = google_service_account.trigger_service_account.project |
| 39 | + role = "roles/eventarc.eventReceiver" |
| 40 | + member = "serviceAccount:${google_service_account.trigger_service_account.email}" |
| 41 | +} |
| 42 | + |
| 43 | +resource "google_cloud_run_service" "default" { |
| 44 | + name = "{{index $.Vars "service_name"}}" |
| 45 | + location = "us-central1" |
| 46 | + |
| 47 | + template { |
| 48 | + spec { |
| 49 | + containers { |
| 50 | + image = "gcr.io/cloudrun/hello" |
| 51 | + ports { |
| 52 | + container_port = 8080 |
| 53 | + } |
| 54 | + } |
| 55 | + container_concurrency = 50 |
| 56 | + timeout_seconds = 100 |
| 57 | + } |
| 58 | + } |
| 59 | + |
| 60 | + traffic { |
| 61 | + percent = 100 |
| 62 | + latest_revision = true |
| 63 | + } |
| 64 | +} |
0 commit comments