2023-01-20 13:54:37 +01:00
|
|
|
resource "opennebula_group" "main" {
|
|
|
|
name = var.group
|
|
|
|
}
|
|
|
|
|
2023-01-19 14:15:52 +01:00
|
|
|
// OpenNebula disk image !
|
|
|
|
resource "opennebula_image" "system" {
|
2023-01-20 13:18:20 +01:00
|
|
|
name = local.system_image_name
|
2023-01-19 14:15:52 +01:00
|
|
|
description = "System disk image"
|
|
|
|
datastore_id = var.one_prod_ds
|
|
|
|
persistent = false
|
|
|
|
//lock = "MANAGE"
|
|
|
|
path = var.system_image_source
|
|
|
|
dev_prefix = "vd"
|
|
|
|
driver = "qcow2"
|
|
|
|
format = "qcow2"
|
|
|
|
permissions = var.imagemode
|
|
|
|
group = var.group
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "opennebula_image" "data" {
|
2023-01-20 13:18:20 +01:00
|
|
|
name = local.data_image_name
|
2023-01-19 14:15:52 +01:00
|
|
|
description = "Data disk image"
|
|
|
|
datastore_id = var.one_prod_ds
|
|
|
|
persistent = true
|
|
|
|
//lock = "MANAGE"
|
|
|
|
path = var.data_image_source
|
|
|
|
dev_prefix = "vd"
|
|
|
|
driver = "qcow2"
|
|
|
|
format = "qcow2"
|
|
|
|
permissions = "660"
|
2023-01-20 13:54:37 +01:00
|
|
|
group = var.group
|
2023-01-19 14:15:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// OpenNebula (VM) Template definition
|
|
|
|
resource "opennebula_template" "vm_template" {
|
|
|
|
name = var.vm_shortname
|
|
|
|
cpu = var.cpu
|
|
|
|
vcpu = var.vcpu
|
|
|
|
memory = var.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.id
|
|
|
|
}
|
|
|
|
disk {
|
|
|
|
image_id = opennebula_image.data.id
|
|
|
|
}
|
|
|
|
|
2023-01-20 13:51:11 +01:00
|
|
|
os {
|
|
|
|
arch = "x86_64"
|
|
|
|
boot = "disk0,nic0"
|
|
|
|
}
|
2023-01-19 14:15:52 +01:00
|
|
|
//labels = var.tag_labels
|
|
|
|
|
|
|
|
dynamic "nic" {
|
|
|
|
for_each = var.network_interfaces
|
|
|
|
|
|
|
|
content {
|
|
|
|
network_id = nic.value.network_id
|
|
|
|
model = "virtio"
|
|
|
|
ip = nic.value.ip
|
|
|
|
}
|
|
|
|
}
|
|
|
|
permissions = "600"
|
|
|
|
group = var.group
|
|
|
|
depends_on = [ opennebula_image.system,
|
|
|
|
opennebula_image.data ]
|
|
|
|
}
|
|
|
|
|
|
|
|
// OpenNebula Virtual Machine
|
|
|
|
resource "opennebula_virtual_machine" "vm" {
|
2023-01-20 13:18:20 +01:00
|
|
|
name = local.fqdn
|
2023-01-19 14:15:52 +01:00
|
|
|
group = var.group
|
|
|
|
template_id = opennebula_template.vm_template.id
|
2023-01-20 13:18:20 +01:00
|
|
|
depends_on = [ opennebula_template.vm_template ]
|
2023-01-19 14:15:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "dns_a_record_set" "vm_dns_a_record" {
|
|
|
|
count = var.dns_a_record == "yes" ? 1 : 0
|
|
|
|
|
|
|
|
zone = var.vm_domain
|
|
|
|
name = var.vm_shortname
|
|
|
|
ttl = 300
|
|
|
|
|
|
|
|
addresses = [ var.network_interfaces[0].ip ]
|
|
|
|
depends_on = [ opennebula_virtual_machine.vm ]
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "dns_cname_record" "vm_dns_cname_record" {
|
|
|
|
for_each = var.dns_cname_record
|
|
|
|
|
|
|
|
zone = var.vm_domain
|
|
|
|
name = each.value
|
2023-01-20 13:18:20 +01:00
|
|
|
cname = "${local.fqdn}."
|
2023-01-19 14:15:52 +01:00
|
|
|
ttl = 300
|
|
|
|
|
|
|
|
depends_on = [ opennebula_virtual_machine.vm ]
|
|
|
|
}
|