-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
87 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
# CloudInit
resource "libvirt_cloudinit_disk" "cloudinit" {
name = "${local.fqdn}-cloudinit.iso"
pool = var.cloudinit_pool_name
user_data = templatefile(
"${path.module}/${local.cloudinit_template}",
{
hostname = var.hostname
fqdn = local.fqdn
admin_users = var.host_admin_users
admin_groups = var.host_admin_groups
root_password = var.host_root_password
})
network_config = templatefile(
"${path.module}/network_config.cfg",
{
ip_address = var.network_ip_address
subnet_mask = var.network_subnet
gateway_ip = var.network_gateway_ip
name_servers = var.network_nameserver_ips
domain = var.domain
})
}
# Disks
resource "libvirt_volume" "main" {
name = "${local.fqdn}.qcow2"
base_volume_id = var.disk_base_volume_id
size = var.disk_size
}
resource "libvirt_volume" "additional_disks" {
for_each = var.additional_disks
name = "${local.fqdn}-${each.key}.qcow2"
size = each.value
}
# Virtual Machine
resource "libvirt_domain" "main" {
name = local.fqdn
memory = var.memory
vcpu = var.vcpus
cloudinit = libvirt_cloudinit_disk.cloudinit.id
autostart = true
disk {
volume_id = libvirt_volume.main.id
}
dynamic "disk" {
for_each = var.additional_disks
content {
volume_id = libvirt_volume.additional_disks[disk.key].id
}
}
network_interface {
bridge = var.network_bridge_name
hostname = local.fqdn
}
console {
type = "pty"
target_type = "serial"
target_port = "0"
}
console {
type = "pty"
target_type = "virtio"
target_port = "1"
}
graphics {
type = "spice"
listen_type = "address"
autoport = true
}
}