-
Notifications
You must be signed in to change notification settings - Fork 1
/
domains.tf
63 lines (58 loc) · 1.76 KB
/
domains.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
resource "libvirt_cloudinit_disk" "cloud_inits" {
for_each = local.domains
name = "cloud_init_${each.key}.iso"
pool = libvirt_pool.disk_pool.name
network_config = templatefile(
"${path.module}/templates/network.cfg",
{
dns_servers: each.value.dns.servers,
dns_search: each.value.dns.search
}
)
user_data = templatefile(
"${path.module}/templates/cloud_init.cfg",
{
hostname = each.key
ssh_key = file(pathexpand(each.value.sshPublicKey))
ansible_playbook = file(pathexpand(lookup(each.value, "ansiblePlaybook", null)))
extra_files = lookup(each.value, "extraFiles", [])
}
)
}
resource "libvirt_domain" "vms" {
for_each = local.domains
autostart = true
name = each.key
vcpu = each.value.cpuCount
memory = each.value.ramSize
cloudinit = libvirt_cloudinit_disk.cloud_inits[each.key].id
# https://bugs.launchpad.net/cloud-images/+bug/1573095
console {
type = "pty"
target_port = "0"
target_type = "serial"
}
disk {
volume_id = libvirt_volume.os_volumes[each.key].id
scsi = true
}
dynamic "disk" {
for_each = toset([
for vol in libvirt_volume.data_volumes :
vol if split("_", vol.name)[0] == each.key
])
content {
volume_id = disk.value.id
scsi = true
}
}
dynamic "network_interface" {
for_each = each.value.networkInterfaces
content {
hostname = each.key
mac = lookup(network_interface.value, "mac", null)
network_id = libvirt_network.networks[network_interface.value.networkName].id
addresses = lookup(network_interface.value, "ip", null) == null ? [] : [network_interface.value.ip]
}
}
}