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" {
default = "vd"
default = "sd"
}
variable "permissions" {
@ -44,7 +44,7 @@ variable "graphics" {
}
variable "one_prod_ds" {
variable "one_image_ds" {
default = "101"
}
@ -52,6 +52,18 @@ variable "one_sys_datastore" {
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
resource "opennebula_image" "system" {
@ -59,23 +71,26 @@ resource "opennebula_image" "system" {
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_10G"
datastore_id = var.one_image_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
// data image not needed now
resource "opennebula_image" "data" {
for_each = {
for ds in local.data_disks : "${ds.vm_key}.${ds.name}" => ds
}
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
dev_prefix = var.dev_prefix
permissions = var.permissions
@ -103,11 +118,19 @@ resource "opennebula_template" "vm_template" {
disk {
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 {
arch = "x86_64"
@ -121,12 +144,17 @@ resource "opennebula_template" "vm_template" {
content {
network_id = nic.value.network_id
model = "virtio"
mac = nic.value.mac
mac = ( nic.value.mac != "" ? nic.value.mac : "" )
ip = ( nic.value.ip != "" ? nic.value.ip : "" )
}
}
permissions = var.permissions
depends_on = [ opennebula_image.system ]
/* Not needed now
depends_on = [ opennebula_image.system,
opennebula_image.data ]
*/
}
resource "opennebula_virtual_machine" "vm" {

View File

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

View File

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