-
Notifications
You must be signed in to change notification settings - Fork 0
/
pubsub.tf
124 lines (108 loc) · 5.41 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# ==============================
# A PubSub topic in this project
# ==============================
resource "google_pubsub_topic" "govuk_integration_database_backups" {
name = "govuk-integration-database-backups"
message_retention_duration = "604800s" # 604800 seconds is 7 days
message_storage_policy {
allowed_persistence_regions = [
var.region,
]
}
}
// Allow the bucket to send notifications to topic
data "google_storage_project_service_account" "default" {}
data "google_iam_policy" "pubsub_topic-govuk_integration_database_backups" {
binding {
role = "roles/pubsub.publisher"
members = [
"serviceAccount:${data.google_storage_project_service_account.default.email_address}"
]
}
}
resource "google_pubsub_topic_iam_policy" "govuk_integration_database_backups" {
topic = google_pubsub_topic.govuk_integration_database_backups.name
policy_data = data.google_iam_policy.pubsub_topic-govuk_integration_database_backups.policy_data
}
# Notify the topic from the bucket
resource "google_storage_notification" "govuk_integration_database_backups" {
bucket = google_storage_bucket.govuk-integration-database-backups.name
payload_format = "JSON_API_V1"
topic = google_pubsub_topic.govuk_integration_database_backups.id
event_types = ["OBJECT_FINALIZE"]
depends_on = [google_pubsub_topic_iam_policy.govuk_integration_database_backups]
}
# Subscribe to the topic (so that it can be monitored in the console)
resource "google_pubsub_subscription" "govuk_integration_database_backups" {
name = "govuk-integration-database-backups"
topic = google_pubsub_topic.govuk_integration_database_backups.name
message_retention_duration = "604800s" # 604800 seconds is 7 days
retain_acked_messages = true
expiration_policy {
ttl = "" # empty string is 'never'
}
enable_message_ordering = false
}
# ===================================================
# A PubSub topic in the govuk-knowledge-graph project
# ===================================================
# Notify the topic from the bucket
resource "google_storage_notification" "govuk_integration_database_backups-govuk_knowledge_graph" {
bucket = google_storage_bucket.govuk-integration-database-backups.name
payload_format = "JSON_API_V1"
topic = "/projects/govuk-knowledge-graph/topics/govuk-integration-database-backups"
event_types = ["OBJECT_FINALIZE"]
depends_on = [google_pubsub_topic_iam_policy.govuk_integration_database_backups]
}
# =======================================================
# A PubSub topic in the govuk-knowledge-graph-staging project
# =======================================================
# Notify the topic from the bucket
resource "google_storage_notification" "govuk_integration_database_backups-govuk_knowledge_graph_staging" {
bucket = google_storage_bucket.govuk-integration-database-backups.name
payload_format = "JSON_API_V1"
topic = "/projects/govuk-knowledge-graph-staging/topics/govuk-integration-database-backups"
event_types = ["OBJECT_FINALIZE"]
depends_on = [google_pubsub_topic_iam_policy.govuk_integration_database_backups]
}
# =======================================================
# A PubSub topic in the govuk-knowledge-graph-dev project
# =======================================================
# Notify the topic from the bucket
resource "google_storage_notification" "govuk_integration_database_backups-govuk_knowledge_graph_dev" {
bucket = google_storage_bucket.govuk-integration-database-backups.name
payload_format = "JSON_API_V1"
topic = "/projects/govuk-knowledge-graph-dev/topics/govuk-integration-database-backups"
event_types = ["OBJECT_FINALIZE"]
depends_on = [google_pubsub_topic_iam_policy.govuk_integration_database_backups]
}
# =========================================================
# Notify a PubSub topic in the govuk-analytics-test project
# =========================================================
resource "google_storage_notification" "support_api_backup_staging" {
bucket = google_storage_bucket.govuk-integration-database-backups.name
payload_format = "JSON_API_V1"
topic = "projects/govuk-analytics-test/topics/support-api-backup-staging"
event_types = ["OBJECT_FINALIZE"]
object_name_prefix = "support-api-postgres/"
}
# =========================================================
# Notify a PubSub topic in the govuk-user-feedback project
# =========================================================
resource "google_storage_notification" "govuk_user_feedback" {
bucket = google_storage_bucket.govuk-integration-database-backups.name
payload_format = "JSON_API_V1"
topic = "projects/govuk-user-feedback/topics/support-api-backup-staging"
event_types = ["OBJECT_FINALIZE"]
object_name_prefix = "support-api-postgres/"
}
# =========================================================
# Notify a PubSub topic in the govuk-user-feedback-dev project
# =========================================================
resource "google_storage_notification" "govuk_user_feedback_dev" {
bucket = google_storage_bucket.govuk-integration-database-backups.name
payload_format = "JSON_API_V1"
topic = "projects/govuk-user-feedback-dev/topics/support-api-backup-staging"
event_types = ["OBJECT_FINALIZE"]
object_name_prefix = "support-api-postgres/"
}