-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
64 lines (53 loc) · 1.91 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
locals {
instance_id = "ses-${substr(sha256(var.instance_name), 0, 16)}"
user_name = "${local.instance_id}-${var.user_name}"
subscribe_bounce_notification = (var.bounce_topic_arn != "" && var.notification_webhook != "")
subscribe_complaint_notification = (var.complaint_topic_arn != "" && var.notification_webhook != "")
subscribe_delivery_notification = (var.delivery_topic_arn != "" && var.notification_webhook != "")
subscribed_webhook = ((local.subscribe_bounce_notification || local.subscribe_complaint_notification || local.subscribe_delivery_notification) ? var.notification_webhook : null)
}
resource "aws_iam_user" "user" {
name = local.user_name
path = "/cf/"
}
resource "aws_iam_access_key" "access_key" {
user = aws_iam_user.user.name
}
resource "aws_iam_user_policy" "user_policy" {
name = format("%s-p", local.user_name)
user = aws_iam_user.user.name
policy = jsonencode({
Version = "2012-10-17"
Statement = [{
Effect = "Allow"
Action = [
"ses:SendEmail",
"ses:SendRawEmail"
]
Resource = var.domain_arn
Condition = {
"ForAnyValue:IpAddress" = {
"aws:SourceIp" = var.source_ips
}
}
}]
})
}
resource "aws_sns_topic_subscription" "bounce_subscription" {
count = (local.subscribe_bounce_notification ? 1 : 0)
topic_arn = var.bounce_topic_arn
protocol = "https"
endpoint = var.notification_webhook
}
resource "aws_sns_topic_subscription" "complaint_subscription" {
count = (local.subscribe_complaint_notification ? 1 : 0)
topic_arn = var.complaint_topic_arn
protocol = "https"
endpoint = var.notification_webhook
}
resource "aws_sns_topic_subscription" "delivery_subscription" {
count = (local.subscribe_delivery_notification ? 1 : 0)
topic_arn = var.delivery_topic_arn
protocol = "https"
endpoint = var.notification_webhook
}