-
Notifications
You must be signed in to change notification settings - Fork 0
/
pubsub.tf
102 lines (82 loc) · 2.84 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
95
96
97
98
99
100
101
102
resource "google_pubsub_topic" "queue" {
project = var.project_id
name = "gateway-${var.instance_name}.queue"
message_storage_policy {
allowed_persistence_regions = [var.region]
}
}
resource "google_pubsub_topic_iam_binding" "queue_publisher" {
project = var.project_id
topic = google_pubsub_topic.queue.name
role = "roles/pubsub.publisher"
members = [
"serviceAccount:${google_service_account.poweb.email}",
"serviceAccount:${google_service_account.cogrpc.email}",
"serviceAccount:${google_service_account.queue.email}",
]
}
resource "google_service_account" "queue_invoker" {
account_id = "gateway-${var.instance_name}-queue-pubsub"
display_name = "Awala Internet Gateway (${var.instance_name}), queue invoker"
}
resource "google_cloud_run_service_iam_binding" "queue_invoker" {
location = google_cloud_run_v2_service.queue.location
service = google_cloud_run_v2_service.queue.name
role = "roles/run.invoker"
members = ["serviceAccount:${google_service_account.queue_invoker.email}"]
}
resource "google_project_service_identity" "pubsub" {
provider = google-beta
project = var.project_id
service = "pubsub.googleapis.com"
}
resource "google_project_iam_binding" "pubsub_token_creator" {
project = var.project_id
role = "roles/iam.serviceAccountTokenCreator"
members = ["serviceAccount:${google_project_service_identity.pubsub.email}"]
}
resource "google_pubsub_subscription" "queue" {
name = "gateway-${var.instance_name}.queue"
topic = google_pubsub_topic.queue.name
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.queue.uri
oidc_token {
service_account_email = google_service_account.queue_invoker.email
}
attributes = {
x-goog-version = "v1"
}
}
retry_policy {
minimum_backoff = "5s"
}
dead_letter_policy {
dead_letter_topic = google_pubsub_topic.queue_dead_letter.id
max_delivery_attempts = 10
}
}
resource "google_pubsub_topic" "queue_dead_letter" {
project = var.project_id
name = "gateway-${var.instance_name}.queue.dead-letter"
message_storage_policy {
allowed_persistence_regions = [var.region]
}
}
resource "google_pubsub_subscription_iam_binding" "queue_dead_letter" {
project = var.project_id
subscription = google_pubsub_subscription.queue.name
role = "roles/pubsub.subscriber"
members = ["serviceAccount:${google_project_service_identity.pubsub.email}", ]
}
resource "google_pubsub_topic_iam_binding" "queue" {
project = var.project_id
topic = google_pubsub_topic.queue_dead_letter.name
role = "roles/pubsub.publisher"
members = ["serviceAccount:${google_project_service_identity.pubsub.email}", ]
}