-
Notifications
You must be signed in to change notification settings - Fork 0
/
letro_pubsub.tf
57 lines (44 loc) · 1.53 KB
/
letro_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
# ===== Incoming messages
resource "google_service_account" "letro_invoker" {
project = var.google_project_id
account_id = "letro-pubsub"
display_name = "Letro, Cloud Run service invoker"
}
resource "google_cloud_run_service_iam_binding" "letro_invoker" {
project = var.google_project_id
location = google_cloud_run_v2_service.letro.location
service = google_cloud_run_v2_service.letro.name
role = "roles/run.invoker"
members = ["serviceAccount:${google_service_account.letro_invoker.email}"]
}
resource "google_pubsub_subscription" "letro_incoming_messages" {
project = var.google_project_id
name = "letro.incoming-messages"
topic = module.endpoint.pubsub_topics.incoming_messages
filter = "hasPrefix(attributes.datacontenttype, \"application/vnd.relaycorp.letro.\")"
ack_deadline_seconds = 10
message_retention_duration = "259200s" # 3 days
retain_acked_messages = false
expiration_policy {
ttl = "" # Never expire
}
push_config {
push_endpoint = google_cloud_run_v2_service.letro.uri
oidc_token {
service_account_email = google_service_account.letro_invoker.email
}
attributes = {
x-goog-version = "v1"
}
}
retry_policy {
minimum_backoff = "5s"
}
}
# ===== Outgoing messages
resource "google_pubsub_topic_iam_member" "letro_outgoing_messages_publisher" {
project = var.google_project_id
topic = module.endpoint.pubsub_topics.outgoing_messages
role = "roles/pubsub.publisher"
member = "serviceAccount:${google_service_account.letro.email}"
}