-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
61 lines (60 loc) · 1.58 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
terraform {
required_version = ">= 0.13"
required_providers {
libvirt = {
source = "dmacvicar/libvirt"
}
}
}
provider "libvirt" {
uri = "qemu:///system"
}
resource "libvirt_volume" "distro-qcow2" {
count = var.hosts
name = "${var.distros[count.index]}.qcow2"
pool = var.pools[count.index]
source = "${path.module}/sources/${var.distros[count.index]}.qcow2"
format = "qcow2"
}
resource "libvirt_cloudinit_disk" "commoninit" {
count = var.hosts
name = "commoninit-${var.distros[count.index]}.iso"
pool = var.pools[count.index]
user_data = templatefile("${path.module}/templates/user_data.tpl", {
host_name = var.distros[count.index]
auth_key = file("${path.module}/.ssh/${var.hostnames[count.index]}.pub")
})
network_config = templatefile("${path.module}/templates/network_config.tpl", {
interface = var.interface
ip_addr = var.ips[count.index]
mac_addr = var.macs[count.index]
})
}
resource "libvirt_domain" "domain-distro" {
count = var.hosts
name = var.hostnames[count.index]
memory = var.memory
vcpu = var.cpu
cpu {
mode = "host-passthrough"
}
cloudinit = element(libvirt_cloudinit_disk.commoninit.*.id, count.index)
network_interface {
network_name = "default"
addresses = [var.ips[count.index]]
mac = var.macs[count.index]
}
console {
type = "pty"
target_port = "0"
target_type = "serial"
}
console {
type = "pty"
target_port = "1"
target_type = "virtio"
}
disk {
volume_id = element(libvirt_volume.distro-qcow2.*.id, count.index)
}
}