fix conflict

This commit is contained in:
Philippe Caseiro 2023-03-03 15:01:44 +01:00
commit 814ef36bb7
3 changed files with 46 additions and 18 deletions

View File

@ -28,7 +28,7 @@ variable "image_format" {
} }
variable "dev_prefix" { variable "dev_prefix" {
default = "vd" default = "sd"
} }
variable "permissions" { variable "permissions" {
@ -44,7 +44,7 @@ variable "graphics" {
} }
variable "one_prod_ds" { variable "one_image_ds" {
default = "101" default = "101"
} }
@ -52,30 +52,45 @@ variable "one_sys_datastore" {
default = "100" default = "100"
} }
locals {
data_disks = flatten([
for vm_key, vm in var.vms : [
for disk in vm.data_disks : {
vm_key = "${vm_key}.${vm.domain}"
name = disk.name
size = disk.size
persist = disk.persistent
}
]
])
}
// system image // system image
resource "opennebula_image" "system" { resource "opennebula_image" "system" {
for_each = var.vms for_each = var.vms
name = "system-${each.key}.${each.value.domain}" name = "system-${each.key}.${each.value.domain}"
description = "System disk for ${each.key}" description = "System disk for ${each.key}"
datastore_id = var.one_prod_ds datastore_id = var.one_image_ds
path = "https://vulcain.cadoles.com/empty_10G" path = "https://vulcain.cadoles.com/empty_20G"
persistent = each.value.system_image_persistent persistent = each.value.system_image_persistent
format = var.image_format format = var.image_format
dev_prefix = var.dev_prefix dev_prefix = var.dev_prefix
permissions = var.permissions permissions = var.permissions
} }
// data image
resource "opennebula_image" "data" {
for_each = var.vms
name = "data-${each.key}.${each.value.domain}" // data image not needed now
path = "https://vulcain.cadoles.com/empty_40G" resource "opennebula_image" "data" {
datastore_id = var.one_prod_ds for_each = {
description = "data disk for ${each.key}" for ds in local.data_disks : "${ds.vm_key}.${ds.name}" => ds
persistent = each.value.data_image_persistent }
name = "${each.value.vm_key}-data-${each.value.name}"
path = "https://vulcain.cadoles.com/empty_${each.value.size}"
datastore_id = var.one_image_ds
description = "Data disk of ${each.value.size} for ${each.value.vm_key}"
persistent = each.value.persist
format = var.image_format format = var.image_format
dev_prefix = var.dev_prefix dev_prefix = var.dev_prefix
permissions = var.permissions permissions = var.permissions
@ -103,11 +118,19 @@ resource "opennebula_template" "vm_template" {
disk { disk {
image_id = opennebula_image.system[each.key].id image_id = opennebula_image.system[each.key].id
} }
disk {
image_id = opennebula_image.data[each.key].id dynamic "disk" {
for_each = {
for ds in local.data_disks : "${ds.vm_key}.${ds.name}" => ds if "${each.key}.${each.value.domain}" == ds.vm_key
}
iterator = current_disk
content {
image_id = opennebula_image.data[current_disk.key].id
}
} }
sched_ds_requirements = ( each.value.sysdatastore != "" ? each.value.sysdatastore : var.one_sys_datastore ) //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}\"" : "" )
os { os {
arch = "x86_64" arch = "x86_64"
@ -121,12 +144,17 @@ resource "opennebula_template" "vm_template" {
content { content {
network_id = nic.value.network_id network_id = nic.value.network_id
model = "virtio" model = "virtio"
mac = nic.value.mac mac = ( nic.value.mac != "" ? nic.value.mac : "" )
ip = ( nic.value.ip != "" ? nic.value.ip : "" )
} }
} }
permissions = var.permissions permissions = var.permissions
depends_on = [ opennebula_image.system ]
/* Not needed now
depends_on = [ opennebula_image.system, depends_on = [ opennebula_image.system,
opennebula_image.data ] opennebula_image.data ]
*/
} }
resource "opennebula_virtual_machine" "vm" { resource "opennebula_virtual_machine" "vm" {

View File

@ -3,4 +3,5 @@ locals {
system_image_name = "system.${local.fqdn}" system_image_name = "system.${local.fqdn}"
system_image_source = var.system_image_source system_image_source = var.system_image_source
data_image_name = "data.${local.fqdn}" data_image_name = "data.${local.fqdn}"
group = "${var.group}"
} }

View File

@ -1,4 +1,3 @@
resource "opennebula_group" "main" { resource "opennebula_group" "main" {
name = var.group name = var.group
} }