-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.tf
90 lines (70 loc) · 1.75 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
# Zone creation
resource "cloudflare_zone" "domain" {
count = var.zone_on ? 1 : 0
zone = var.domain
plan = var.plan
account_id = data.cloudflare_accounts.main.accounts[0].id
}
# Zone settings
resource "cloudflare_zone_settings_override" "domain" {
zone_id = cloudflare_zone.domain[0].id
settings {
ssl = "full"
always_use_https = "on"
automatic_https_rewrites = "on"
cache_level = "aggressive"
development_mode = "off"
}
depends_on = [
cloudflare_zone.domain
]
}
# Naked A record
resource "cloudflare_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"
depends_on = [
cloudflare_zone.domain
]
}
# Naked AAAA record
resource "cloudflare_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"
depends_on = [
cloudflare_zone.domain
]
}
# www > naked domain
resource "cloudflare_record" "domain_www" {
count = length(var.ipv4)
zone_id = cloudflare_zone.domain[0].id
name = "www"
content = var.www_cname == "" ? var.domain : var.www_cname
proxied = "true"
type = "CNAME"
depends_on = [
cloudflare_zone.domain
]
}
# Other A, CNAME, MX, TXT records
resource "cloudflare_record" "records" {
for_each = local.final_records
zone_id = cloudflare_zone.domain[0].id
name = each.value.name
content = each.value.value
type = each.value.type
priority = each.value.priority
proxied = each.value.proxied
depends_on = [
cloudflare_zone.domain
]
}