-
Notifications
You must be signed in to change notification settings - Fork 6
/
ses.tf
143 lines (112 loc) · 4.63 KB
/
ses.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
locals {
custom_sending_domain_dkim_records = distinct(flatten([
for cd in aws_ses_domain_dkim.custom_sending_domains : [
for token in cd.dkim_tokens : {
domain = cd.domain
token = token
}
]
]))
}
resource "aws_sesv2_email_identity" "notification-canada-ca" {
email_identity = var.domain
}
resource "aws_ses_domain_dkim" "notification-canada-ca" {
domain = var.domain
}
# TODO: SES Domain Validation Records Programmatically
resource "aws_ses_identity_notification_topic" "notification-canada-ca-bounce-topic" {
topic_arn = var.notification_canada_ca_ses_callback_arn
notification_type = "Bounce"
identity = aws_sesv2_email_identity.notification-canada-ca.email_identity
include_original_headers = false
}
resource "aws_ses_identity_notification_topic" "notification-canada-ca-delivery-topic" {
topic_arn = var.notification_canada_ca_ses_callback_arn
notification_type = "Delivery"
identity = aws_sesv2_email_identity.notification-canada-ca.email_identity
include_original_headers = false
}
resource "aws_ses_identity_notification_topic" "notification-canada-ca-complaint-topic" {
topic_arn = var.notification_canada_ca_ses_callback_arn
notification_type = "Complaint"
identity = aws_sesv2_email_identity.notification-canada-ca.email_identity
include_original_headers = false
}
resource "aws_ses_domain_mail_from" "notification-canada-ca" {
domain = aws_sesv2_email_identity.notification-canada-ca.email_identity
mail_from_domain = "bounce.${aws_sesv2_email_identity.notification-canada-ca.email_identity}"
}
###
# Receiving emails
###
resource "aws_sesv2_email_identity" "notification-canada-ca-receiving" {
# Email receiving with SES is available in only 3 regions
# so we use us-east-1
# https://docs.aws.amazon.com/general/latest/gr/ses.html
provider = aws.us-east-1
email_identity = var.domain
}
resource "aws_ses_domain_dkim" "notification-canada-ca-receiving" {
provider = aws.us-east-1
domain = var.domain
}
resource "aws_ses_receipt_rule_set" "main" {
provider = aws.us-east-1
rule_set_name = "main"
}
resource "aws_ses_active_receipt_rule_set" "main" {
provider = aws.us-east-1
rule_set_name = aws_ses_receipt_rule_set.main.rule_set_name
}
###
# Additional custom sending domains for emails
###
resource "aws_sesv2_email_identity" "custom_sending_domains" {
for_each = var.ses_custom_sending_domains
email_identity = each.value
}
resource "aws_ses_domain_dkim" "custom_sending_domains" {
for_each = var.ses_custom_sending_domains
domain = each.value
}
resource "aws_ses_identity_notification_topic" "custom_sending_domains_bounce_topic" {
for_each = var.ses_custom_sending_domains
topic_arn = var.notification_canada_ca_ses_callback_arn
notification_type = "Bounce"
identity = aws_sesv2_email_identity.custom_sending_domains[each.value].email_identity
include_original_headers = false
}
resource "aws_ses_identity_notification_topic" "custom_sending_domains_delivery_topic" {
for_each = var.ses_custom_sending_domains
topic_arn = var.notification_canada_ca_ses_callback_arn
notification_type = "Delivery"
identity = aws_sesv2_email_identity.custom_sending_domains[each.value].email_identity
include_original_headers = false
}
resource "aws_ses_identity_notification_topic" "custom_sending_domains_complaint_topic" {
for_each = var.ses_custom_sending_domains
topic_arn = var.notification_canada_ca_ses_callback_arn
notification_type = "Complaint"
identity = aws_sesv2_email_identity.custom_sending_domains[each.value].email_identity
include_original_headers = false
}
resource "aws_ses_domain_mail_from" "custom_sending_domains" {
for_each = var.ses_custom_sending_domains
domain = aws_sesv2_email_identity.custom_sending_domains[each.value].email_identity
mail_from_domain = "bounce.${aws_sesv2_email_identity.custom_sending_domains[each.value].email_identity}"
}
### SES receiving emails lambda image
resource "aws_ses_receipt_rule" "ses_receiving_emails_inbound-to-lambda-arn" {
provider = aws.us-east-1
name = "ses_receiving_emails_inbound-to-lambda"
rule_set_name = aws_ses_receipt_rule_set.main.rule_set_name
recipients = [var.domain]
enabled = true
scan_enabled = true
lambda_action {
function_arn = var.lambda_ses_receiving_emails_image_arn
invocation_type = "Event"
position = 1
}
}