-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
47 lines (42 loc) · 1.6 KB
/
main.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
locals {
default_webhook_templates = {
# https://docs.aws.amazon.com/AmazonS3/latest/userguide/notification-content-structure.html
s3 = {
event = "S3 {{ body.detail.reason }}",
resource = {
"prefect.resource.id" = "s3.bucket.{{ body.detail.bucket.name }}",
"object-key" = "{{ body.detail.object.key }}",
}
}
# https://cloud.google.com/storage/docs/pubsub-notifications
gcs = {
event = "GCS {{ body.message.attributes.eventType }}",
resource = {
"prefect.resource.id" = "gcs.bucket.{{ body.message.attributes.bucketId }}",
"object-key" = "{{ body.message.attributes.objectId }}",
}
}
}
}
resource "prefect_webhook" "webhook" {
name = var.webhook_name
description = "Webhook for cloud bucket event notifications"
enabled = true
template = jsonencode(coalesce(var.webhook_template, local.default_webhook_templates[var.bucket_type]))
}
module "s3" {
source = "./modules/s3"
count = var.bucket_type == "s3" ? 1 : 0
bucket_name = var.bucket_name
topic_name = var.topic_name
bucket_event_notification_types = var.bucket_event_notification_types
prefect_webhook_url = prefect_webhook.webhook.endpoint
}
module "gcs" {
source = "./modules/gcs"
count = var.bucket_type == "gcs" ? 1 : 0
bucket_name = var.bucket_name
topic_name = var.topic_name
bucket_event_notification_types = var.bucket_event_notification_types
prefect_webhook_url = prefect_webhook.webhook.endpoint
}