118 lines
2.5 KiB
HCL
118 lines
2.5 KiB
HCL
variable "vms" {
|
|
type = map
|
|
description = "Virtual Machines description"
|
|
}
|
|
|
|
variable "image_format" {
|
|
default = "qcow2"
|
|
}
|
|
|
|
variable "dev_prefix" {
|
|
default = "vd"
|
|
}
|
|
|
|
variable "permissions" {
|
|
default = "600"
|
|
}
|
|
|
|
variable "graphics" {
|
|
default = {
|
|
keymap = "fr"
|
|
listen = "0.0.0.0"
|
|
type = "VNC"
|
|
}
|
|
|
|
}
|
|
|
|
variable "one_prod_ds" {
|
|
default = "101"
|
|
}
|
|
|
|
variable "one_sys_datastore" {
|
|
default = "100"
|
|
}
|
|
|
|
|
|
// system image
|
|
resource "opennebula_image" "system" {
|
|
for_each = var.vms
|
|
|
|
name = "system-${each.key}.${each.value.domain}"
|
|
description = "System disk for ${each.key}"
|
|
datastore_id = var.one_prod_ds
|
|
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
|
|
}
|
|
|
|
// data image
|
|
resource "opennebula_image" "data" {
|
|
for_each = var.vms
|
|
|
|
name = "data-${each.key}.${each.value.domain}"
|
|
path = "https://vulcain.cadoles.com/empty_40G"
|
|
datastore_id = var.one_prod_ds
|
|
description = "data disk for ${each.key}"
|
|
persistent = each.value.data_image_persistent
|
|
format = var.image_format
|
|
dev_prefix = var.dev_prefix
|
|
permissions = var.permissions
|
|
}
|
|
|
|
resource "opennebula_template" "vm_template" {
|
|
for_each = var.vms
|
|
|
|
name = "${each.key}.${each.value.domain}"
|
|
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
|
|
}
|
|
disk {
|
|
image_id = opennebula_image.data[each.key].id
|
|
}
|
|
|
|
sched_ds_requirements = ( each.value.sysdatastore != "" ? each.value.sysdatastore : var.one_sys_datastore )
|
|
|
|
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"
|
|
mac = nic.value.mac
|
|
}
|
|
}
|
|
permissions = var.permissions
|
|
depends_on = [ opennebula_image.system,
|
|
opennebula_image.data ]
|
|
}
|
|
|
|
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 ]
|
|
}
|