-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.tf
91 lines (81 loc) · 2.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
91
resource "libvirt_network" "vm_network" {
autostart = var.network_autostart
name = var.network_name
mode = var.network_mode
domain = var.network_domain
addresses = var.network_cidr
bridge = var.network_bridge
mtu = var.network_mtu
dns {
enabled = var.network_dns_enabled
local_only = var.network_dns_local
dynamic "hosts" {
for_each = concat(
data.libvirt_network_dns_host_template.hosts.*.rendered
)
content {
hostname = hosts.value.hostname
ip = hosts.value.ip
}
}
dynamic "srvs" {
for_each = data.libvirt_network_dns_srv_template.srv_records.*.rendered
content {
service = srvs.value["service"]
protocol = srvs.value["protocol"]
domain = srvs.value["domain"]
target = srvs.value["target"]
port = srvs.value["port"]
priority = srvs.value["priority"]
weight = srvs.value["weight"]
}
}
}
dhcp {
enabled = var.network_dhcp_enabled
}
dnsmasq_options {
dynamic "options" {
for_each = concat(
data.libvirt_network_dnsmasq_options_template.options.*.rendered,
)
content {
option_name = options.value.option_name
option_value = options.value.option_value
}
}
}
dynamic "routes" {
for_each = var.network_routes
content {
cidr = routes.key
gateway = routes.value
}
}
xml {
xslt = var.network_dhcp_range_start != null && var.network_dhcp_range_start != null ? templatefile("${path.module}/templates/dhcp-range-patch.xslt", {
network_dhcp_range_start = var.network_dhcp_range_start
network_dhcp_range_end = var.network_dhcp_range_end
}) : null
}
}
data "libvirt_network_dnsmasq_options_template" "options" {
count = length(var.network_dnsmasq_options)
option_name = keys(var.network_dnsmasq_options)[count.index]
option_value = values(var.network_dnsmasq_options)[count.index]
}
data "libvirt_network_dns_host_template" "hosts" {
count = length(var.network_dns_entries)
hostname = keys(var.network_dns_entries)[count.index]
ip = values(var.network_dns_entries)[count.index]
}
data "libvirt_network_dns_srv_template" "srv_records" {
count = length(var.network_dns_srv_records)
service = values(var.network_dns_srv_records)[count.index].service
protocol = values(var.network_dns_srv_records)[count.index].protocol
domain = values(var.network_dns_srv_records)[count.index].domain
target = values(var.network_dns_srv_records)[count.index].target
port = values(var.network_dns_srv_records)[count.index].port
priority = values(var.network_dns_srv_records)[count.index].priority
weight = values(var.network_dns_srv_records)[count.index].weight
}