-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.tf
65 lines (57 loc) · 2.16 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
terraform {
required_providers {
dnsimple = {
source = "dnsimple/dnsimple"
version = ">= 1.0"
}
util = {
source = "poseidon/util"
version = "0.3.0"
}
}
}
provider "dnsimple" {
token = var.dnsimple_token
account = var.dnsimple_account
sandbox = var.dnsimple_sandbox
user_agent = "DNSimple-Consul-Terraform"
}
module "service_records" {
source = "./modules/service-records"
for_each = local.consul_services
consul_service = each.value.service
defaults = each.value.defaults
zone_records = each.value.zone_records
}
locals {
consul_services = {
for id, service in var.services :
id => {
"name" = service.name,
"defaults" = {
"zone_name" = lookup(service.meta, "dnsimple_default_zone", null),
"record_type" = lookup(service.meta, "dnsimple_default_record_type", "A"),
"record_ttl" = lookup(service.meta, "dnsimple_default_record_ttl", 3600),
},
"zone_records" = concat([{
"zone_name" = lookup(service.meta, "dnsimple_zone_name", null),
"record_name" = lookup(service.meta, "dnsimple_record_name", null),
"record_content" = lookup(service.meta, "dnsimple_record_content", null),
"record_type" = lookup(service.meta, "dnsimple_record_type", null),
"record_ttl" = lookup(service.meta, "dnsimple_record_ttl", null),
"record_priority" = lookup(service.meta, "dnsimple_record_priority", null),
}], [
for n in range(0, 60) :
{
"zone_name" = lookup(service.meta, "dnsimple_zone_name-${n}", null),
"record_name" = lookup(service.meta, "dnsimple_record_name-${n}", null),
"record_content" = lookup(service.meta, "dnsimple_record_content-${n}", null),
"record_type" = lookup(service.meta, "dnsimple_record_type-${n}", null),
"record_ttl" = lookup(service.meta, "dnsimple_record_ttl-${n}", null),
"record_priority" = lookup(service.meta, "dnsimple_record_priority-${n}", null),
} if lookup(service.meta, "dnsimple_record_content-${n}", null) != null
])
"service" = service,
}
}
}