-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.tf
More file actions
68 lines (66 loc) · 1.89 KB
/
main.tf
File metadata and controls
68 lines (66 loc) · 1.89 KB
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
locals {
windows_start_script = "net user Admin ${try(random_pet.windows[0].id, "")}"
base_context = {
NETWORK = "YES"
SET_HOSTNAME = "${var.vm_name}"
SSH_PUBLIC_KEY = "$USER[SSH_PUBLIC_KEY]"
GROW_ROOTFS = "YES"
}
windows_context = {
START_SCRIPT = "net user Admin ${try(random_pet.windows[0].id, "")}"
}
linux_context = {
START_SCRIPT = "${var.start_script}"
}
final_context = merge(local.base_context, var.custom_context, (var.is_windows ? local.windows_context : local.linux_context))
}
resource "opennebula_virtual_machine" "main" {
name = var.vm_name
description = "VM"
cpu = coalesce(var.cpu, data.opennebula_template.template.cpu)
vcpu = coalesce(var.vcpu, data.opennebula_template.template.vcpu, 4)
memory = try((var.memory * 1024), data.opennebula_template.template.memory)
cpumodel {
model = "host-passthrough"
}
template_id = data.opennebula_template.template.id
context = local.final_context
os {
arch = "x86_64"
boot = "disk0"
}
disk {
image_id = data.opennebula_image.image.id
size = local.rootdisk_size
}
dynamic "disk" {
for_each = var.disks
content {
size = disk.value.size * 1024
volatile_type = "fs"
}
}
on_disk_change = "RECREATE"
nic {
network_id = data.opennebula_virtual_network.main.id
security_groups = [opennebula_security_group.main.id]
}
dynamic "nic" {
for_each = var.vsc ? [0] : []
content {
network_id = data.opennebula_virtual_network.vsc.id
security_groups = [opennebula_security_group.main.id]
}
}
dynamic "template_section" {
for_each = var.is_windows ? [0] : []
content {
name = "TOPOLOGY"
elements = {
"CORES" = coalesce(var.vcpu, data.opennebula_template.template.vcpu),
"SOCKETS" = 1,
"THREADS" = 1,
}
}
}
}