-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.tf
114 lines (90 loc) · 2.55 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
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
resource "aws_ses_domain_identity" "this" {
provider = aws.identity
domain = var.domain
}
resource "aws_ses_identity_policy" "this" {
count = length(var.authorized_accounts) == 0 ? 0 : 1
provider = aws.identity
identity = aws_ses_domain_identity.this.arn
name = "${local.name}-delegated-senders"
policy = data.aws_iam_policy_document.this.json
}
resource "aws_route53_record" "domain_identity" {
provider = aws.route53
for_each = data.aws_route53_zone.domain
name = "_amazonses.${var.domain}"
records = [aws_ses_domain_identity.this.verification_token]
ttl = 3600
type = "TXT"
zone_id = each.value.zone_id
}
resource "aws_route53_record" "dkim" {
count = var.create_records ? 3 : 0
provider = aws.route53
ttl = 3600
type = "CNAME"
zone_id = data.aws_route53_zone.domain[local.zone_domain].zone_id
name = join(
".",
[
element(aws_ses_domain_dkim.mail.dkim_tokens, count.index),
"_domainkey",
var.domain
]
)
records = [
join(
".",
[
element(aws_ses_domain_dkim.mail.dkim_tokens, count.index),
"dkim.amazonses.com"
]
)
]
}
resource "aws_ses_domain_identity_verification" "mail" {
count = var.create_records ? 1 : 0
provider = aws.identity
domain = aws_ses_domain_identity.this.id
}
resource "aws_ses_domain_dkim" "mail" {
domain = aws_ses_domain_identity.this.domain
provider = aws.identity
}
resource "aws_ses_identity_notification_topic" "bounce" {
provider = aws.identity
topic_arn = aws_sns_topic.this.arn
notification_type = "Bounce"
identity = aws_ses_domain_identity.this.domain
}
resource "aws_ses_identity_notification_topic" "complaint" {
provider = aws.identity
topic_arn = aws_sns_topic.this.arn
notification_type = "Complaint"
identity = aws_ses_domain_identity.this.domain
}
resource "aws_sns_topic" "this" {
provider = aws.identity
name = "${local.name}-notifications"
tags = var.tags
}
data "aws_iam_policy_document" "this" {
provider = aws.identity
statement {
actions = ["SES:SendEmail", "SES:SendRawEmail"]
resources = [aws_ses_domain_identity.this.arn]
principals {
identifiers = var.authorized_accounts
type = "AWS"
}
}
}
data "aws_route53_zone" "domain" {
for_each = var.create_records ? toset([local.zone_domain]) : []
provider = aws.route53
name = each.value
}
locals {
name = join("-", concat(var.namespace, split(".", var.domain)))
zone_domain = coalesce(var.zone_domain, var.domain)
}