Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow instantiating more environments #49

Merged
merged 3 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
156 changes: 9 additions & 147 deletions dns.tf
Original file line number Diff line number Diff line change
@@ -1,27 +1,5 @@
# TODO create NS and SOA records

resource "aws_route53_zone" "apex" {
name = "seagl.org"
}

resource "aws_ses_domain_identity" "seagl" {
domain = "seagl.org"
}

# SPF
resource "aws_route53_record" "route_53_root_txt" {
zone_id = aws_route53_zone.apex.id
name = ""
type = "TXT"
ttl = "300"
records = [
"v=spf1 include:_spf.google.com include:amazonses.com include:40081384.spf02.hubspotemail.net include:_spf.osuosl.org ~all",
"google-site-verification=9Hrl69xXhSeoBOVlnmpOYOSS6fYeiuGehZjHlyPZx3g"
]
}

resource "aws_route53_record" "route_53_cloud_txt" {
zone_id = aws_route53_zone.apex.id
zone_id = module.production_env.zone_id
name = "cloud.seagl.org"
type = "TXT"
ttl = "300"
Expand All @@ -30,32 +8,12 @@ resource "aws_route53_record" "route_53_cloud_txt" {
]
}

# DKIM
resource "aws_ses_domain_identity" "email_domain_identity" {
domain = var.email_domain_name
}

resource "aws_ses_domain_dkim" "email_dkim" {
domain = aws_ses_domain_identity.email_domain_identity.domain
}

resource "aws_route53_record" "email_dkim_records" {
count = 3
zone_id = aws_route53_zone.apex.id
name = "${element(aws_ses_domain_dkim.email_dkim.dkim_tokens, count.index)}._domainkey.${var.email_domain_name}"
type = "CNAME"
ttl = "300"
records = [
"${element(aws_ses_domain_dkim.email_dkim.dkim_tokens, count.index)}.dkim.amazonses.com",
]
}

resource "aws_route53_record" "email_dkim_hubspot_records" {
for_each = {
"hs1-40081384" : "seagl-org.hs12a.dkim.hubspotemail.net",
"hs2-40081384" : "seagl-org.hs12b.dkim.hubspotemail.net"
}
zone_id = aws_route53_zone.apex.id
zone_id = module.production_env.zone_id
name = "${each.key}._domainkey.${var.email_domain_name}"
type = "CNAME"
ttl = "300"
Expand All @@ -64,32 +22,19 @@ resource "aws_route53_record" "email_dkim_hubspot_records" {
]
}

resource "aws_route53_record" "route_53_dmarc_txt" {
zone_id = aws_route53_zone.apex.id
name = "_dmarc.${var.email_domain_name}"
type = "TXT"
ttl = "300"
records = [
"v=DMARC1;p=quarantine;rua=mailto:dmarc-rpt@seagl.org"
]
# TODO remove this; we do DKIM-based verification instead.
resource "aws_ses_domain_identity" "email_domain_identity" {
domain = var.email_domain_name
}

# TODO remove this. It's unnecessary because the domain is verified.
# It's still here only to make a refactoring `plan` clean.
resource "aws_ses_email_identity" "email" {
email = "sre@seagl.org"
}

resource "aws_route53_record" "dokku_wildcard" {
zone_id = aws_route53_zone.apex.id
name = "*.seagl.org"
type = "CNAME"
ttl = "300"
records = [
"dokku.seagl.org"
]
}

resource "aws_route53_record" "cloud-a" {
zone_id = aws_route53_zone.apex.id
zone_id = module.production_env.zone_id
name = "cloud.seagl.org"
type = "A"
ttl = "300"
Expand All @@ -99,94 +44,11 @@ resource "aws_route53_record" "cloud-a" {
}

resource "aws_route53_record" "cloud-aaaa" {
zone_id = aws_route53_zone.apex.id
zone_id = module.production_env.zone_id
name = "cloud.seagl.org"
type = "AAAA"
ttl = "300"
records = [
"2605:bc80:3010:104::8cd3:935"
]
}

resource "aws_route53_record" "mailu-test-a" {
zone_id = aws_route53_zone.apex.id
name = "mail.mail-test.seagl.org"
type = "A"
# TODO increase all these Mailu TTLs
ttl = "300"
records = [
"140.211.167.146"
]
}

resource "aws_route53_record" "mailu-test-mx" {
zone_id = aws_route53_zone.apex.id
name = "mail-test.seagl.org"
type = "MX"
ttl = "300"
records = [
"10 mail.mail-test.seagl.org."
]
}

resource "aws_route53_record" "mailu-test-spf" {
zone_id = aws_route53_zone.apex.id
name = "mail-test.seagl.org"
type = "TXT"
ttl = "300"
records = [
# This diverges from Mailu's rec: they wanted to include a:mail.mail-test.seagl.org too
"v=spf1 mx ~all"
]
}

resource "aws_route53_record" "mailu-test-autoconfig-srv" {
# grep SRV | sed -e 's/ 600 IN SRV /": "/' -e 's/^/"/' -e 's/$/",/' -e 's/ mail.mail-test.seagl.org.//' -e 's/.mail-test.seagl.org.//'
for_each = {
"_imap._tcp" : "20 1 143",
"_pop3._tcp" : "20 1 110",
"_submission._tcp" : "20 1 587",
"_autodiscover._tcp" : "10 1 443",
"_submissions._tcp" : "10 1 465",
"_imaps._tcp" : "10 1 993",
"_pop3s._tcp" : "10 1 995"
}
zone_id = aws_route53_zone.apex.id
name = "${each.key}.mail-test.seagl.org"
type = "SRV"
ttl = "300"
records = [
"${each.value} mail.mail-test.seagl.org."
]
}

resource "aws_route53_record" "mailu-test-autoconfig-cname" {
zone_id = aws_route53_zone.apex.id
name = "autoconfig.mail-test.seagl.org"
type = "CNAME"
ttl = "300"
records = [
"mail.mail-test.seagl.org."
]
}

resource "aws_route53_record" "mailu-test-dkim" {
zone_id = aws_route53_zone.apex.id
name = "dkim._domainkey.mail-test.seagl.org"
type = "TXT"
ttl = "300"
records = [
"v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1Jw/diiAFRmarcHsr/KkGvfr22CVA5xTJTWRInvKi2My7PbWjhLSGNx7XcJw1DCcfOGb1cdArjNmYDmmG6VRRTQjCr2RWBSihIRLodnc+KPeS2Xnipi0JdNg7CTCNVQfA+znlKoWqalTT0nKrlDf87vhLmltU4wOYnrmvtZvtHkdwd9GA7hxMdHu4LnW\"\"X2VK0itMcPCBqIUvyOSIHJ8c7i8VPmcV+G6VDquepNsmFN0zcvNXAosqaWOHCnzCGzvQiwm6Lbq4vMxUsU6BLUv1JiPq3zXtqQ4tp6VynpLIy5VaF4XI5fyibsKTPuzI0d58tuiCrgCCMy5T9BmkCnQAzQIDAQAB"
]
}

resource "aws_route53_record" "mailu-test-dmarc" {
zone_id = aws_route53_zone.apex.id
name = "_dmarc.mail-test.seagl.org"
type = "TXT"
ttl = "300"
records = [
# TODO this email doesn't seem to be created automatically
"v=DMARC1; p=reject; rua=mailto:dmarc@mail-test.seagl.org; ruf=mailto:dmarc@mail-test.seagl.org; adkim=s; aspf=s"
]
}
149 changes: 149 additions & 0 deletions env/dns.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
# TODO create NS and SOA records

resource "aws_route53_zone" "apex" {
name = var.zone_name
}

resource "aws_route53_record" "delegation-ns" {
count = var.attach_to_zone != null ? 1 : 0
zone_id = var.attach_to_zone.zone_id
name = aws_route53_zone.apex.name
type = "NS"
ttl = "300"
records = aws_route53_zone.apex.name_servers
}

resource "aws_ses_domain_identity" "main" {
domain = var.zone_name
}

# SPF
resource "aws_route53_record" "route_53_root_txt" {
zone_id = aws_route53_zone.apex.id
name = ""
type = "TXT"
ttl = "300"
records = concat([
"v=spf1 include:_spf.google.com include:amazonses.com include:40081384.spf02.hubspotemail.net include:_spf.osuosl.org ~all",
], var.additional_root_txts)
}

# DKIM
resource "aws_ses_domain_dkim" "email_dkim" {
domain = aws_ses_domain_identity.main.domain
}

resource "aws_route53_record" "email_dkim_records" {
count = 3
zone_id = aws_route53_zone.apex.id
name = "${element(aws_ses_domain_dkim.email_dkim.dkim_tokens, count.index)}._domainkey.${var.zone_name}"
type = "CNAME"
ttl = "300"
records = [
"${element(aws_ses_domain_dkim.email_dkim.dkim_tokens, count.index)}.dkim.amazonses.com",
]
}

resource "aws_route53_record" "route_53_dmarc_txt" {
zone_id = aws_route53_zone.apex.id
name = "_dmarc.${var.zone_name}"
type = "TXT"
ttl = "300"
records = [
"v=DMARC1;p=quarantine;rua=mailto:dmarc-rpt@${var.zone_name}"
]
}

resource "aws_route53_record" "dokku_wildcard" {
zone_id = aws_route53_zone.apex.id
name = "*.${var.zone_name}"
type = "CNAME"
ttl = "300"
records = [
"dokku.${var.zone_name}"
]
}

resource "aws_route53_record" "mailu-test-a" {
zone_id = aws_route53_zone.apex.id
name = "mail.mail-test.${var.zone_name}"
type = "A"
# TODO increase all these Mailu TTLs
ttl = "300"
records = [
"140.211.167.146"
]
Comment on lines +73 to +75
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be parameterized?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't bother because we're just going to delete Mailu test records anyway in favor of our prod deployment, managed by the simple_vm module.

}

resource "aws_route53_record" "mailu-test-mx" {
zone_id = aws_route53_zone.apex.id
name = "mail-test.${var.zone_name}"
type = "MX"
ttl = "300"
records = [
"10 mail.mail-test.${var.zone_name}."
]
}

resource "aws_route53_record" "mailu-test-spf" {
zone_id = aws_route53_zone.apex.id
name = "mail-test.${var.zone_name}"
type = "TXT"
ttl = "300"
records = [
# This diverges from Mailu's rec: they wanted to include a:mail.mail-test.seagl.org too
"v=spf1 mx ~all"
]
}

resource "aws_route53_record" "mailu-test-autoconfig-srv" {
# grep SRV | sed -e 's/ 600 IN SRV /": "/' -e 's/^/"/' -e 's/$/",/' -e 's/ mail.mail-test.seagl.org.//' -e 's/.mail-test.seagl.org.//'
for_each = {
"_imap._tcp" : "20 1 143",
"_pop3._tcp" : "20 1 110",
"_submission._tcp" : "20 1 587",
"_autodiscover._tcp" : "10 1 443",
"_submissions._tcp" : "10 1 465",
"_imaps._tcp" : "10 1 993",
"_pop3s._tcp" : "10 1 995"
}
zone_id = aws_route53_zone.apex.id
name = "${each.key}.mail-test.${var.zone_name}"
type = "SRV"
ttl = "300"
records = [
"${each.value} mail.mail-test.${var.zone_name}."
]
}

resource "aws_route53_record" "mailu-test-autoconfig-cname" {
zone_id = aws_route53_zone.apex.id
name = "autoconfig.mail-test.${var.zone_name}"
type = "CNAME"
ttl = "300"
records = [
"mail.mail-test.${var.zone_name}."
]
}

resource "aws_route53_record" "mailu-test-dkim" {
zone_id = aws_route53_zone.apex.id
name = "dkim._domainkey.mail-test.${var.zone_name}"
type = "TXT"
ttl = "300"
records = [
# TODO parameterize this
"v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1Jw/diiAFRmarcHsr/KkGvfr22CVA5xTJTWRInvKi2My7PbWjhLSGNx7XcJw1DCcfOGb1cdArjNmYDmmG6VRRTQjCr2RWBSihIRLodnc+KPeS2Xnipi0JdNg7CTCNVQfA+znlKoWqalTT0nKrlDf87vhLmltU4wOYnrmvtZvtHkdwd9GA7hxMdHu4LnW\"\"X2VK0itMcPCBqIUvyOSIHJ8c7i8VPmcV+G6VDquepNsmFN0zcvNXAosqaWOHCnzCGzvQiwm6Lbq4vMxUsU6BLUv1JiPq3zXtqQ4tp6VynpLIy5VaF4XI5fyibsKTPuzI0d58tuiCrgCCMy5T9BmkCnQAzQIDAQAB"
]
}

resource "aws_route53_record" "mailu-test-dmarc" {
zone_id = aws_route53_zone.apex.id
name = "_dmarc.mail-test.${var.zone_name}"
type = "TXT"
ttl = "300"
records = [
# TODO this email doesn't seem to be created automatically
"v=DMARC1; p=reject; rua=mailto:dmarc@mail-test.${var.zone_name}; ruf=mailto:dmarc@mail-test.${var.zone_name}; adkim=s; aspf=s"
]
}
4 changes: 2 additions & 2 deletions mailu.tf → env/mailu.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module "mailu-vm" {
source = "./simple_vm"
source = "../simple_vm"
name = "mailu"
ports = [22, 25, 80, 110, 143, 443, 465, 587, 993, 995]
instance_type = "m1.medium"
network = "general_servers2"
disk_size = 30
dns_zone = aws_route53_zone.apex
dns_zone = aws_route53_zone.apex
}
2 changes: 1 addition & 1 deletion nextcloud-office.tf → env/nextcloud-office.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module "nc-office-vm" {
source = "./simple_vm"
source = "../simple_vm"
name = "nc-office"
ports = [22, 80, 443]
instance_type = "m1.small"
Expand Down
3 changes: 3 additions & 0 deletions env/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "zone_id" {
value = aws_route53_zone.apex.id
}
17 changes: 17 additions & 0 deletions env/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
variable "zone_name" {
description = "FQDN that will be suffixed to all hosts in the environment"
type = string
}

variable "attach_to_zone" {
description = "Route 53 zone object to attach (via NS record) the environment's zone to"
default = null
type = object({
zone_id = string
})
}

variable "additional_root_txts" {
description = "Additional TXT records to publish at the root of the zone"
type = list(string)
}
4 changes: 0 additions & 4 deletions imports.tf

This file was deleted.

Loading
Loading