2023-02-02 14:43:16 +01:00
|
|
|
variable "vms" {
|
|
|
|
type = map
|
|
|
|
description = "Virtual Machines description"
|
|
|
|
}
|
|
|
|
|
|
|
|
variable "image_format" {
|
|
|
|
default = "qcow2"
|
|
|
|
}
|
|
|
|
|
|
|
|
variable "dev_prefix" {
|
2023-02-27 14:13:58 +01:00
|
|
|
default = "sd"
|
2023-02-02 14:43:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
variable "permissions" {
|
|
|
|
default = "600"
|
|
|
|
}
|
|
|
|
|
|
|
|
variable "graphics" {
|
|
|
|
default = {
|
|
|
|
keymap = "fr"
|
|
|
|
listen = "0.0.0.0"
|
|
|
|
type = "VNC"
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-03-02 10:26:50 +01:00
|
|
|
variable "one_image_ds" {
|
2023-02-02 14:43:16 +01:00
|
|
|
default = "101"
|
|
|
|
}
|
|
|
|
|
2023-02-24 06:03:44 +01:00
|
|
|
variable "one_sys_datastore" {
|
|
|
|
default = "100"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-02-02 14:43:16 +01:00
|
|
|
// system image
|
|
|
|
resource "opennebula_image" "system" {
|
|
|
|
for_each = var.vms
|
|
|
|
|
|
|
|
name = "system-${each.key}.${each.value.domain}"
|
|
|
|
description = "System disk for ${each.key}"
|
2023-03-02 10:26:50 +01:00
|
|
|
datastore_id = var.one_image_ds
|
2023-02-02 14:43:16 +01:00
|
|
|
path = "https://vulcain.cadoles.com/empty_20G"
|
|
|
|
persistent = each.value.system_image_persistent
|
|
|
|
format = var.image_format
|
|
|
|
dev_prefix = var.dev_prefix
|
|
|
|
permissions = var.permissions
|
|
|
|
}
|
|
|
|
|
2023-02-27 14:13:58 +01:00
|
|
|
/* data image not needed now
|
2023-02-02 14:43:16 +01:00
|
|
|
resource "opennebula_image" "data" {
|
|
|
|
for_each = var.vms
|
|
|
|
|
|
|
|
name = "data-${each.key}.${each.value.domain}"
|
|
|
|
path = "https://vulcain.cadoles.com/empty_40G"
|
2023-03-02 10:26:50 +01:00
|
|
|
datastore_id = var.one_image_ds
|
2023-02-02 14:43:16 +01:00
|
|
|
description = "data disk for ${each.key}"
|
|
|
|
persistent = each.value.data_image_persistent
|
|
|
|
format = var.image_format
|
|
|
|
dev_prefix = var.dev_prefix
|
|
|
|
permissions = var.permissions
|
2023-02-27 14:13:58 +01:00
|
|
|
}*/
|
2023-02-02 14:43:16 +01:00
|
|
|
|
|
|
|
resource "opennebula_template" "vm_template" {
|
|
|
|
for_each = var.vms
|
|
|
|
|
2023-02-24 10:40:18 +01:00
|
|
|
name = "${each.key}.${each.value.domain}"
|
2023-02-02 14:43:16 +01:00
|
|
|
cpu = each.value.cpu
|
|
|
|
vcpu = each.value.vcpu
|
|
|
|
memory = each.value.ram
|
|
|
|
graphics {
|
|
|
|
keymap = var.graphics.keymap
|
|
|
|
listen = var.graphics.listen
|
|
|
|
type = var.graphics.type
|
|
|
|
}
|
|
|
|
context = {
|
|
|
|
SET_HOSTNAME = "$NAME"
|
|
|
|
DNS_HOSTNAME = "YES"
|
|
|
|
NETWORK = "YES"
|
|
|
|
SSH_PUBLIC_KEY = "$USER[SSH_PUBLIC_KEY]"
|
|
|
|
USERNAME = "root"
|
|
|
|
}
|
|
|
|
disk {
|
|
|
|
image_id = opennebula_image.system[each.key].id
|
|
|
|
}
|
2023-02-27 14:13:58 +01:00
|
|
|
|
|
|
|
/* Not needed now
|
2023-02-02 14:43:16 +01:00
|
|
|
disk {
|
|
|
|
image_id = opennebula_image.data[each.key].id
|
|
|
|
}
|
2023-02-27 14:13:58 +01:00
|
|
|
*/
|
2023-02-02 14:43:16 +01:00
|
|
|
|
2023-02-27 14:20:52 +01:00
|
|
|
//sched_ds_requirements = ( each.value.sysdatastore != "" ? "ID=\"${each.value.sysdatastore}\"" : "ID=\"${var.one_sys_datastore}\"" )
|
|
|
|
sched_ds_requirements = ( each.value.sysdatastore != "" ? "ID=\"${each.value.sysdatastore}\"" : "" )
|
2023-02-24 06:03:44 +01:00
|
|
|
|
2023-02-02 14:43:16 +01:00
|
|
|
os {
|
|
|
|
arch = "x86_64"
|
|
|
|
boot = "disk0,nic0"
|
|
|
|
}
|
|
|
|
//labels = var.tag_labels
|
|
|
|
|
|
|
|
dynamic "nic" {
|
|
|
|
for_each = each.value.network_interfaces
|
|
|
|
|
|
|
|
content {
|
|
|
|
network_id = nic.value.network_id
|
|
|
|
model = "virtio"
|
2023-03-02 10:12:45 +01:00
|
|
|
mac = ( nic.value.mac != "" ? nic.value.mac : "" )
|
|
|
|
ip = ( nic.value.ip != "" ? nic.value.ip : "" )
|
2023-02-02 14:43:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
permissions = var.permissions
|
2023-02-27 14:16:49 +01:00
|
|
|
depends_on = [ opennebula_image.system ]
|
|
|
|
|
|
|
|
/* Not needed now
|
2023-02-02 14:43:16 +01:00
|
|
|
depends_on = [ opennebula_image.system,
|
|
|
|
opennebula_image.data ]
|
2023-02-27 14:16:49 +01:00
|
|
|
*/
|
2023-02-02 14:43:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "opennebula_virtual_machine" "vm" {
|
|
|
|
for_each = var.vms
|
|
|
|
name = "${each.key}.${each.value.domain}"
|
|
|
|
template_id = opennebula_template.vm_template[each.key].id
|
|
|
|
depends_on = [ opennebula_template.vm_template ]
|
|
|
|
}
|