Skip to content

Commit ffccc40

Browse files
tommyreddadDawid212
authored andcommitted
Fixes issue #21482 related to google_eventarc_trigger name with Firestore sources (GoogleCloudPlatform#13137)
1 parent b6a3dde commit ffccc40

File tree

3 files changed

+90
-0
lines changed

3 files changed

+90
-0
lines changed

mmv1/products/eventarc/Trigger.yaml

+11
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,16 @@ examples:
8383
service_account_id: trigger-sa
8484
service_name: some-service
8585
exclude_docs: true
86+
- name: eventarc_trigger_with_firestore_source
87+
primary_resource_id: primary
88+
vars:
89+
trigger_name: some-trigger
90+
service_account_id: trigger-sa
91+
service_name: some-service
92+
database_id: some-database
93+
test_env_vars:
94+
project_id: 'PROJECT_NAME'
95+
exclude_docs: true
8696
parameters:
8797
- name: location
8898
type: String
@@ -97,6 +107,7 @@ properties:
97107
required: true
98108
immutable: true
99109
diff_suppress_func: tpgresource.CompareSelfLinkOrResourceName
110+
custom_expand: templates/terraform/custom_expand/eventarc_trigger_name.go.tmpl
100111
- name: uid
101112
type: String
102113
description: Output only. Server assigned unique identifier for the trigger. The value is a UUID4 string and guaranteed to remain unchanged until the resource is deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{{/*
2+
The license inside this block applies to this file
3+
Copyright 2025 Google Inc.
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/ -}}
13+
func expand{{$.GetPrefix}}{{$.TitlelizeProperty}}(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
14+
return expandToRegionalLongForm("projects/%s/locations/%s/triggers/%s", v, d, config)
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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

Comments
 (0)