-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.tf
97 lines (83 loc) · 3.09 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
# see https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/route53_zone
data "aws_route53_zone" "zone" {
zone_id = var.zone_id
}
locals {
autodiscover_record = "autodiscover.mail.${var.workmail_zone}.awsapps.com."
mx_record = "${var.mx_priority} inbound-smtp.${var.workmail_zone}.amazonaws.com."
zone_apex_txt_record = concat(var.spf_record, var.apex_txt_record_append)
zone_name = data.aws_route53_zone.zone.name // NOTE: trailing period is added by data source
}
# see https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_record
resource "aws_route53_record" "mx" {
zone_id = var.zone_id
name = local.zone_name
type = "MX"
ttl = var.record_ttl
records = [
local.mx_record
]
}
# enable autodiscovery service for Outlook and other clients
# see https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_record
resource "aws_route53_record" "autodiscover" {
zone_id = var.zone_id
name = "autodiscover.${local.zone_name}"
type = "CNAME"
ttl = var.record_ttl
records = [
local.autodiscover_record
]
}
# see https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ses_domain_identity
resource "aws_ses_domain_identity" "main" {
domain = local.zone_name
}
# see https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ses_domain_mail_from
resource "aws_ses_domain_mail_from" "main" {
domain = aws_ses_domain_identity.main.domain
mail_from_domain = "${var.mail_from_subdomain}.${aws_ses_domain_identity.main.domain}"
}
# see https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_record
resource "aws_route53_record" "verification_token" {
zone_id = var.zone_id
name = "_amazonses.${local.zone_name}"
type = "TXT"
ttl = "600"
records = [
aws_ses_domain_identity.main.verification_token
]
}
# see https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ses_domain_dkim
resource "aws_ses_domain_dkim" "main" {
domain = aws_ses_domain_identity.main.domain
}
# see https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_record
resource "aws_route53_record" "dkim" {
count = 3
zone_id = var.zone_id
name = "${element(aws_ses_domain_dkim.main.dkim_tokens, count.index)}._domainkey.${local.zone_name}"
type = "CNAME"
ttl = "600"
records = [
"${element(aws_ses_domain_dkim.main.dkim_tokens, count.index)}.dkim.amazonses.com."
]
}
# see https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_record
resource "aws_route53_record" "zone_apex_txt" {
zone_id = var.zone_id
name = local.zone_name
type = "TXT"
ttl = var.record_ttl
records = local.zone_apex_txt_record
}
# see https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_record
resource "aws_route53_record" "dmarc" {
zone_id = var.zone_id
name = "_dmarc.${local.zone_name}"
type = "TXT"
ttl = var.record_ttl
records = [
var.dmarc_record
]
}