-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.tf
102 lines (81 loc) · 1.99 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
98
99
100
101
102
# Zone creation
resource "cloudflare_zone" "domain" {
count = var.zone_on ? 1 : 0
name = var.domain
account = {
id = data.cloudflare_account.main.account_id
}
}
# Zone settings
locals {
zone_settings = {
ssl = "full"
always_use_https = "on"
automatic_https_rewrites = "on"
cache_level = "aggressive"
development_mode = "off"
}
}
resource "cloudflare_zone_setting" "all" {
for_each = local.zone_settings
zone_id = cloudflare_zone.domain[0].id
setting_id = each.key
id = each.key
value = each.value
depends_on = [
cloudflare_zone.domain
]
}
# Naked A record
resource "cloudflare_dns_record" "domain_ipv4" {
count = length(var.ipv4)
zone_id = cloudflare_zone.domain[0].id
name = var.domain
content = var.ipv4[count.index]
proxied = "true"
type = "A"
ttl = 1
depends_on = [
cloudflare_zone.domain
]
}
# Naked AAAA record
resource "cloudflare_dns_record" "domain_ipv6" {
count = length(var.ipv6)
zone_id = cloudflare_zone.domain[0].id
name = var.domain
content = var.ipv6[count.index]
proxied = "true"
type = "AAAA"
ttl = 1
depends_on = [
cloudflare_zone.domain
]
}
# www > naked domain
resource "cloudflare_dns_record" "domain_www" {
count = length(var.ipv4)
zone_id = cloudflare_zone.domain[0].id
name = "www.${var.domain}"
content = var.www_cname == "" ? var.domain : var.www_cname
proxied = "true"
type = "CNAME"
ttl = 1
depends_on = [
cloudflare_zone.domain
]
}
# Other A, CNAME, MX, TXT records
resource "cloudflare_dns_record" "records" {
for_each = local.final_records
zone_id = cloudflare_zone.domain[0].id
name = each.value.name == var.domain ? each.value.name : "${each.value.name}.${var.domain}"
content = each.value.value
type = each.value.type
priority = each.value.priority
proxied = each.value.proxied
ttl = 1
depends_on = [
cloudflare_zone.domain
]
}