-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathmain.tf
89 lines (78 loc) · 2.14 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
terraform {
required_version = ">= 1.0"
required_providers {
libvirt = {
source = "dmacvicar/libvirt"
version = ">= 0.7.0"
}
}
}
resource "libvirt_domain" "virt-machine" {
count = var.vm_count
name = format("${var.vm_hostname_prefix}%02d", count.index + var.index_start)
memory = var.memory
cpu {
mode = var.cpu_mode
}
vcpu = var.vcpu
autostart = var.autostart
qemu_agent = true
cloudinit = element(libvirt_cloudinit_disk.commoninit[*].id, count.index)
network_interface {
bridge = var.bridge
wait_for_lease = true
hostname = format("${var.vm_hostname_prefix}%02d", count.index + var.index_start)
}
xml {
xslt = templatefile("${path.module}/xslt/template.tftpl", var.xml_override)
}
console {
type = "pty"
target_port = "0"
target_type = "serial"
}
console {
type = "pty"
target_type = "virtio"
target_port = "1"
}
disk {
volume_id = element(libvirt_volume.volume-qcow2[*].id, count.index)
}
dynamic "disk" {
for_each = var.additional_disk_ids
content {
volume_id = disk.value
}
}
dynamic "filesystem" {
for_each = var.share_filesystem.source != null ? [var.share_filesystem.source] : []
content {
source = var.share_filesystem.source
target = var.share_filesystem.target
readonly = var.share_filesystem.readonly
accessmode = var.share_filesystem.mode
}
}
graphics {
type = var.graphics
listen_type = "address"
autoport = true
}
provisioner "remote-exec" {
inline = [
"echo \"Virtual Machine \"$(hostname)\" is UP!\"",
"date"
]
connection {
type = "ssh"
user = var.ssh_admin
host = self.network_interface[0].addresses[0]
private_key = try(file(var.ssh_private_key), var.ssh_private_key, null)
timeout = "2m"
bastion_host = var.bastion_host
bastion_user = var.bastion_user
bastion_private_key = try(file(var.bastion_ssh_private_key), var.bastion_ssh_private_key, null)
}
}
}