This repository has been archived by the owner on Jun 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.tf
81 lines (71 loc) · 2.1 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
provider "aws" {
region = "us-east-1"
profile = var.aws_profile
alias = "us-east-1"
}
# SES domian verification
resource "aws_ses_domain_identity" "this" {
provider = aws.us-east-1
domain = var.domain_name
}
resource "aws_ses_domain_identity_verification" "this" {
depends_on = [aws_route53_record.ses_verification]
provider = aws.us-east-1
domain = aws_ses_domain_identity.this.id
}
resource "aws_route53_record" "ses_verification" {
zone_id = var.route53_zone_id
name = "_amazonses.${aws_ses_domain_identity.this.id}"
type = "TXT"
ttl = "600"
records = [aws_ses_domain_identity.this.verification_token]
}
# SES DKIM verification
resource "aws_ses_domain_dkim" "this" {
provider = aws.us-east-1
domain = aws_ses_domain_identity.this.domain
}
resource "aws_route53_record" "dkim" {
count = 3
zone_id = var.route53_zone_id
name = format(
"%s._domainkey.%s",
element(aws_ses_domain_dkim.this.dkim_tokens, count.index),
var.domain_name,
)
type = "CNAME"
ttl = "600"
records = ["${element(aws_ses_domain_dkim.this.dkim_tokens, count.index)}.dkim.amazonses.com"]
}
# SES Mail From record
resource "aws_ses_domain_mail_from" "this" {
provider = aws.us-east-1
domain = aws_ses_domain_identity.this.domain
mail_from_domain = "mail.${var.domain_name}"
}
# SPF validaton record
resource "aws_route53_record" "spf_mail_from" {
zone_id = var.route53_zone_id
name = aws_ses_domain_mail_from.this.mail_from_domain
type = "TXT"
ttl = "600"
records = ["v=spf1 include:amazonses.com -all"]
}
resource "aws_route53_record" "spf_domain" {
zone_id = var.route53_zone_id
name = var.domain_name
type = "TXT"
ttl = "600"
records = ["v=spf1 include:amazonses.com -all"]
}
# Sending MX Record
data "aws_region" "current" {
provider = aws.us-east-1
}
resource "aws_route53_record" "mx_send_mail_from" {
zone_id = var.route53_zone_id
name = aws_ses_domain_mail_from.this.mail_from_domain
type = "MX"
ttl = "600"
records = ["10 feedback-smtp.${data.aws_region.current.name}.amazonses.com"]
}