Skip to content

Commit 42af42a

Browse files
committed
Simplify record generator
1 parent 93a8efc commit 42af42a

2 files changed

Lines changed: 6 additions & 14 deletions

File tree

dns/cloudflare/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ resource "cloudflare_dns_record" "records" {
1717
count = length(module.record_generator.records)
1818
zone_id = data.cloudflare_zones.domain.result[0].id
1919
name = module.record_generator.records[count.index].name
20-
content = module.record_generator.records[count.index].value
20+
content = lookup(module.record_generator.records[count.index], "value", null)
2121
type = module.record_generator.records[count.index].type
2222
ttl = 1
23-
data = module.record_generator.records[count.index].data
23+
data = lookup(module.record_generator.records[count.index], "data", null)
2424
}
2525

2626
output "hostnames" {

dns/record_generator/main.tf

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ locals {
4747
type = "A"
4848
name = join(".", [key, var.name])
4949
value = values["public_ip"]
50-
data = null
5150
}
5251
],
5352
flatten([
@@ -57,7 +56,6 @@ locals {
5756
type = "A"
5857
name = join(".", [vhost, var.name])
5958
value = values["public_ip"]
60-
data = null
6159
}
6260
]
6361
if contains(values["tags"], var.vhost_tag)
@@ -67,16 +65,14 @@ locals {
6765
type = "A"
6866
name = var.name
6967
value = values["public_ip"]
70-
data = null
7168
}
7269
if contains(values["tags"], var.domain_tag)
7370
],
7471
flatten([
7572
for key, values in var.public_instances : [
7673
for alg in keys(values["hostkeys"]) : {
77-
type = "SSHFP"
78-
name = join(".", [key, var.name])
79-
value = null
74+
type = "SSHFP"
75+
name = join(".", [key, var.name])
8076
data = {
8177
algorithm = local.SSHFP_SPEC["ssh-${alg}"]
8278
type = 2 # SHA256
@@ -88,9 +84,8 @@ locals {
8884
flatten([
8985
for key, values in var.public_instances : [
9086
for alg in keys(values["hostkeys"]) : {
91-
type = "SSHFP"
92-
name = var.name
93-
value = null
87+
type = "SSHFP"
88+
name = var.name
9489
data = {
9590
algorithm = local.SSHFP_SPEC["ssh-${alg}"]
9691
type = 2 # SHA256
@@ -106,19 +101,16 @@ locals {
106101
type = "TXT"
107102
name = var.name
108103
value = "\"v=spf1 a -all\""
109-
data = null
110104
},
111105
{
112106
type = "TXT"
113107
name = local.dkim_public_key != "" ? "default._domainkey.${var.name}" : var.name
114108
value = local.dkim_public_key != "" ? join(" ", formatlist("\"%s\"", regexall(".{1,255}", "v=DKIM1; k=rsa; p=${local.dkim_public_key}"))) : "No DKIM public key defined for this domain"
115-
data = null
116109
},
117110
{
118111
type = "TXT"
119112
name = local.dkim_public_key != "" ? "_dmarc.${var.name}" : var.name
120113
value = local.dkim_public_key != "" ? "\"v=DMARC1; p=reject\"" : "No DMARC policy defined for this domain"
121-
data = null
122114
},
123115
]
124116
}

0 commit comments

Comments
 (0)