-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
170 lines (143 loc) · 3.33 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
terraform {
required_version = ">= 0.13"
required_providers {
libvirt = {
source = "nixpkgs/libvirt"
//source = "dmacvicar/libvirt"
version = "0.6.11"
}
}
}
resource "libvirt_pool" "os_images" {
name = "os_images"
type = "dir"
path = "/tmp/terraform-provider-libvirt-pool-images"
}
/*
resource "libvirt_pool" "vm_disks" {
name = "vm_disks"
type = "dir"
path = "/dev/sdb1"
}
*/
data "template_file" "user_data" {
template = file("${path.module}/user_data.yml")
}
data "template_file" "network_config" {
template = file("${path.module}/network_config.yml")
}
resource "libvirt_cloudinit_disk" "commoninit" {
name = "commoninit.iso"
user_data = data.template_file.user_data.rendered
//network_config = data.template_file.network_config.rendered
pool = libvirt_pool.os_images.name
}
resource "libvirt_network_v2" "vm_bridge" {
name = "vm_bridge"
forward {
mode = "route"
}
/* bridge {
name = "guestbr0"
}*/
autostart = true
ip {
address = "160.94.179.162"
dhcp {
dynamic "host" {
for_each = local.member_vms
/*
content {
mac = host.value.network_interface.0.mac
ip = host.value.network_interface.0.addresses.0
}*/
content {
mac = host.value.mac
ip = host.value.address
}
}
}
}
}
resource "libvirt_volume" "member_disk" {
for_each = local.member_vms
name = "${each.key}_disk"
//pool = libvirt_pool.vm_disks.name
pool = "vm_disks"
base_volume_copy = true
base_volume_id = libvirt_volume.debian_image.id
//base_volume_pool = libvirt_pool.os_images.name
base_volume_pool = "vm_disks"
size = each.value.disk
}
resource "libvirt_domain" "member_vm" {
for_each = local.member_vms
name = each.key
memory = "2048"
vcpu = 2
cloudinit = libvirt_cloudinit_disk.commoninit.id
network_interface {
network_id = libvirt_network_v2.vm_bridge.id # TODO(tny): causes a cycle
mac = each.value.mac
# network_name = "guestbr0"
addresses = [ each.value.address ]
hostname = each.key
wait_for_lease = true
}
# depends_on = [ libvirt_network_v2.vm_bridge ]
console {
type = "pty"
target_port = "0"
target_type = "serial"
}
console {
type = "pty"
target_type = "virtio"
target_port = "1"
}
disk {
volume_id = libvirt_volume.member_disk[each.key].id
}
}
/*
resource "libvirt_volume" "member_disk" {
name = "alexa818_disk"
//pool = libvirt_pool.vm_disks.name
pool = "vm_disks"
base_volume_copy = true
base_volume_id = libvirt_volume.debian_image.id
//base_volume_pool = libvirt_pool.os_images.name
base_volume_pool = "vm_disks"
size = 25 * 1024 * 1024 * 1024
}
resource "libvirt_domain" "member_vm" {
name = "alexa818"
memory = "2048"
vcpu = 2
cloudinit = libvirt_cloudinit_disk.commoninit.id
network_interface {
network_id = libvirt_network_v2.vm_bridge.id
addresses = [ "160.94.179.174" ]
hostname = "alexa818"
wait_for_lease = true
}
console {
type = "pty"
target_port = "0"
target_type = "serial"
}
console {
type = "pty"
target_type = "virtio"
target_port = "1"
}
disk {
volume_id = libvirt_volume.alexa818_disk.id
}
}
*/
/*
resource "libvirt_domain" "pan00111" {
name = "andrew"
}
*/