-
Notifications
You must be signed in to change notification settings - Fork 0
/
pubsub.tf
94 lines (75 loc) · 3.04 KB
/
pubsub.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
* Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* Create Pub/Sub topics to capture both prompts and responses
* This module also creates the subscription that writes the raw prompts/response data to the appropriate BigQuery table
*/
resource "google_project_service_identity" "pubsub_sa" {
provider = google-beta
project = module.project-services.project_id
service = "pubsub.googleapis.com"
depends_on = [time_sleep.wait_after_apis]
}
resource "google_project_iam_member" "pubsub_sa_auth" {
project = module.project-services.project_id
for_each = toset([
"roles/bigquery.metadataViewer",
"roles/bigquery.dataEditor",
]
)
role = each.key
member = "serviceAccount:${google_project_service_identity.pubsub_sa.email}"
}
resource "google_pubsub_topic" "refunds_topics" {
project = module.project-services.project_id
for_each = toset(var.refund_resource_purpose)
name = "gemini-multimodal-demo-refunds-${each.key}"
labels = var.labels
message_retention_duration = "86600s"
depends_on = [google_project_service_identity.pubsub_sa]
}
resource "google_pubsub_subscription" "refunds_subs" {
project = module.project-services.project_id
for_each = toset(var.refund_resource_purpose)
topic = google_pubsub_topic.refunds_topics[each.key].name
name = "write-to-bq-refunds-${each.key}"
bigquery_config {
table = "${module.project-services.project_id}.${google_bigquery_dataset.lineage_dataset.dataset_id}.refunds_${each.key}"
use_table_schema = true
write_metadata = true
}
depends_on = [google_bigquery_dataset.lineage_dataset, google_pubsub_topic.refunds_topics]
}
resource "google_pubsub_topic" "review_topics" {
project = module.project-services.project_id
for_each = toset(var.review_resource_purpose)
name = "gemini-multimodal-demo-reviews-${each.key}"
labels = var.labels
message_retention_duration = "86600s"
depends_on = [google_project_service_identity.pubsub_sa]
}
resource "google_pubsub_subscription" "review_subs" {
project = module.project-services.project_id
for_each = toset(var.review_resource_purpose)
topic = google_pubsub_topic.review_topics[each.key].name
name = "write-to-bq-reviews-${each.key}"
bigquery_config {
table = "${module.project-services.project_id}.${google_bigquery_dataset.lineage_dataset.dataset_id}.reviews_${each.key}"
use_table_schema = true
write_metadata = true
}
depends_on = [google_bigquery_dataset.lineage_dataset, google_pubsub_topic.review_topics]
}