-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mta-sts.tf
61 lines (52 loc) · 1.53 KB
/
mta-sts.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
locals {
mta_sts_content = join("\n", [
"version: STSv1",
"mode: enforce",
"mx: ${cloudflare_record.mx[keys(local.email_domain_zones)[0]].value}",
"max_age: 604800",
])
}
resource "cloudflare_worker_script" "mta-sts" {
for_each = local.email_domain_zones
account_id = var.cloudflare_account_id
name = "mta-sts-${replace(each.value.zone, ".", "-")}"
content = <<EOC
async function handleRequest(request) {
return new Response(`${local.mta_sts_content}`, {
headers: {
'content-type': 'text/plain',
}
})
}
addEventListener('fetch', event => {
return event.respondWith(handleRequest(event.request));
})
EOC
}
resource "cloudflare_worker_route" "mta-sts" {
for_each = local.email_domain_zones
zone_id = each.value.id
pattern = "mta-sts.${each.value.zone}/.well-known/mta-sts.txt"
script_name = cloudflare_worker_script.mta-sts[each.key].name
}
resource "cloudflare_record" "mta-sts" {
for_each = local.email_domain_zones
depends_on = [
cloudflare_worker_route.mta-sts,
]
zone_id = each.value.id
type = "CNAME"
name = "mta-sts"
value = "${cloudflare_worker_script.mta-sts[each.key].name}.${var.cloudflare_workers_subdomain}.workers.dev"
proxied = true
}
resource "cloudflare_record" "_mta-sts" {
for_each = local.email_domain_zones
depends_on = [
cloudflare_worker_route.mta-sts,
]
zone_id = each.value.id
type = "TXT"
name = "_mta-sts"
value = "v=STSv1; id=${md5(local.mta_sts_content)};"
}