Skip to content

Commit

Permalink
init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Walter Derezinski committed Mar 5, 2020
1 parent ab47ff0 commit 04b4bc9
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 2 deletions.
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
# terraform-aws-route53-fastmail
Setups a route53 zone for fastmail with needed MX, SPF, and TXT resources.
# Terraform AWS Route53 Fastmail module

Add the needed DNS records to an AWS Route53 zone. The following items are added.

- MX records for in1-smtp.messagingengine.com and in2-smtp.messagingengine.com.
- SPF records
- The _domainkey record for fastmail to validate the domain
- CALDAV auto discovery record
- CARDDAV auto discovery record
- IMAPS auto discovery record
- SUBMISSION auto discovery record
- Configure web access with default mail.<domain>
- Optional configuration for mailchimp to send mail as your domain
7 changes: 7 additions & 0 deletions locals.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

locals {
zone_id = var.zone_id
ttl = var.ttl
extra_spf = var.enable_mailchimp ? "include:servers.mcsv.net ${var.extra_spf}" : var.extra_spf
web_hostname = var.web_hostname
}
118 changes: 118 additions & 0 deletions route53.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@

data aws_route53_zone zone {
zone_id = local.zone_id
}

resource aws_route53_record mx-0 {
zone_id = data.aws_route53_zone.zone.zone_id
name = data.aws_route53_zone.zone.name
type = "MX"
ttl = local.ttl

records = [
"10 in1-smtp.messagingengine.com.",
"20 in2-smtp.messagingengine.com"
]
}

resource aws_route53_record mx-1 {
zone_id = data.aws_route53_zone.zone.zone_id
name = "*.${data.aws_route53_zone.zone.name}"
type = "MX"
ttl = local.ttl

records = [
"10 in1-smtp.messagingengine.com.",
"20 in2-smtp.messagingengine.com"
]
}

resource aws_route53_record spf {
zone_id = data.aws_route53_zone.zone.zone_id
name = data.aws_route53_zone.zone.name
type = "SPF"
ttl = local.ttl

records = [
"v=spf1 include:spf.messagingengine.com ${local.extra_spf} ?all"
]
}

resource aws_route53_record txt {
zone_id = data.aws_route53_zone.zone.zone_id
name = data.aws_route53_zone.zone.name
type = "TXT"
ttl = local.ttl

records = [
"v=spf1 include:spf.messagingengine.com ${local.extra_spf} ?all"
]
}

resource aws_route53_record domainkey {
count = 3
zone_id = data.aws_route53_zone.zone.zone_id
name = "fm${count.index}._domainkey.${data.aws_route53_zone.zone.name}"
type = "CNAME"
ttl = local.ttl

records = [
"fm${count.index}.${data.aws_route53_zone.zone.name}fmhosted.com."
]
}

resource aws_route53_record caldav {
zone_id = data.aws_route53_zone.zone.zone_id
name = "_caldavs_.tcp.${data.aws_route53_zone.zone.name}"
type = "SRV"
ttl = local.ttl

records = [
"0 1 443 caldav.fastmail.com."
]
}

resource aws_route53_record carddav {
zone_id = data.aws_route53_zone.zone.zone_id
name = "_carddav._tcp.${data.aws_route53_zone.zone.name}"
type = "SRV"
ttl = local.ttl

records = [
"0 1 443 carddav.fastmail.com."
]
}

resource aws_route53_record imaps {
zone_id = data.aws_route53_zone.zone.zone_id
name = "_imaps._tcp.${data.aws_route53_zone.zone.name}"
type = "SRV"
ttl = local.ttl

records = [
"0 1 993 imap.fastmail.com."
]
}

resource aws_route53_record submission {
zone_id = data.aws_route53_zone.zone.zone_id
name = "_submission._tcp.${data.aws_route53_zone.zone.name}"
type = "SRV"
ttl = local.ttl

records = [
"0 1 587 smtp.fastmail.com."
]
}

resource aws_route53_record mail {
zone_id = data.aws_route53_zone.zone.zone_id
name = "${local.web_hostname}.${data.aws_route53_zone.zone.name}"
type = "A"
ttl = local.ttl

records = [
"66.111.4.147",
"66.111.4.148"
]
}
4 changes: 4 additions & 0 deletions settings.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

terraform {
required_version = "> 0.12.0"
}
23 changes: 23 additions & 0 deletions variables-optional.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
variable extra_spf {
type = string
default = ""
description = "If you need to add extra configuration information to the SPF record."
}

variable ttl {
type = number
default = 3600
description = "The DNS TTL for all records."
}

variable enable_mailchimp {
type = bool
default = false
description = "Add the required for SPF and TXT records for mail to be sent from mailchimp."
}

variable web_hostname {
type = "string"
default = "mail"
description = "The hostname to use for web access."
}
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

variable zone_id {
type = string
description = "The route53 zone id"
}

0 comments on commit 04b4bc9

Please sign in to comment.