-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.tf
75 lines (64 loc) · 1.73 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
resource "libvirt_volume" "root" {
name = "${var.hostname}_root"
pool = "kvm_storage_pool"
source = "images/ubuntu-${var.ubuntu_version}-server-cloudimg-amd64.raw"
}
resource "libvirt_volume" "data" {
name = "${var.hostname}_data"
pool = "kvm_storage_pool"
size = "${var.data_partition_size}"
format = "raw"
}
resource "libvirt_cloudinit_disk" "cloudinit" {
name = "${var.hostname}_cloudinit.iso"
pool = "kvm_storage_pool"
user_data = "${data.template_file.user_data.rendered}"
network_config = "${data.template_file.network_config.rendered}"
}
data "template_file" "user_data" {
template = "${file("cloudinit/${var.hostname}_user_data.cfg")}"
}
data "template_file" "network_config" {
template = "${file("cloudinit/${var.hostname}_network_config.cfg")}"
}
resource "libvirt_domain" "host" {
# init
name = "${var.hostname}"
metadata = "${var.metadata}"
vcpu = "${var.vcpu}"
memory = "${var.memory}"
running = "${var.running}"
autostart = "${var.autostart}"
cloudinit = "${libvirt_cloudinit_disk.cloudinit.id}"
# file systems
disk {
volume_id = "${libvirt_volume.root.id}"
}
disk {
volume_id = "${libvirt_volume.data.id}"
}
# networks
network_interface {
network_id = "${var.networks_id["internal"]}"
addresses = "${var.networks_addr["internal"]}"
}
network_interface {
network_id = "${var.networks_id["private"]}"
addresses = "${var.networks_addr["private"]}"
}
network_interface {
network_id = "${var.networks_id["public"]}"
addresses = "${var.networks_addr["public"]}"
}
# console
console {
type = "pty"
target_port = "0"
target_type = "serial"
}
console {
type = "pty"
target_type = "virtio"
target_port = "1"
}
}