Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VM: Add support for VALIDATE attribute of RAW vector attribute #583

Open
LKHN opened this issue Dec 30, 2024 · 0 comments
Open

VM: Add support for VALIDATE attribute of RAW vector attribute #583

LKHN opened this issue Dec 30, 2024 · 0 comments

Comments

@LKHN
Copy link

LKHN commented Dec 30, 2024

Description

Due the lack of validate argument of the raw parameters and value of the VALIDATE attribute is set to yes by default on the server side, It is not possible to implement a VM Template as Terraform configuration when the VALIDATE attribute should be set to no to able to pass raw data inside the DATA.

for example to enable secure boot with the help of RAW vector attribute, we can use:

RAW = [
  TYPE = "kvm",
  VALIDATE = "no",
  DATA = "<os firmware='efi'><firmware><feature enabled='yes' name='secure-boot'/><feature enabled='yes' name='enrolled-keys'/></firmware></os>"
]

So, it would nice to be able to write it as:

raw {
  type     = "kvm"
  validate = "no"
  data     = "<os firmware='efi'><firmware><feature enabled='yes' name='secure-boot'/><feature enabled='yes' name='enrolled-keys'/></firmware></os>"
}

See: https://docs.opennebula.io/6.10/management_and_operations/references/template.html#hypervisor-section

New or affected resources and data sources

  • resources/opennebula_template
  • resources/opennebula_virtual_machine

Potential terraform configuration

terraform {
  required_providers {
    opennebula = {
      source  = "OpenNebula/opennebula"
      version = ">= 1.4.1"
    }
  }
}


variable "datastore_id" {
  type     = number
  default  = ""
  nullable = false
}

variable "network_id" {
  type     = number
  default  = ""
  nullable = false
}


provider "opennebula" {
  endpoint = ""
  username = ""
  password = ""
}

resource "opennebula_image" "almalinux_kitten_10_x86_64" {
  name         = "AlmaLinux-Kitten-OpenNebula-10-20241227.0.x86_64"
  description  = "The official AlmaLinux OS Kitten 10 OpenNebula image"
  datastore_id = var.datastore_id
  path         = "https://kitten.repo.almalinux.org/10-kitten/cloud/x86_64/images/AlmaLinux-Kitten-OpenNebula-10-20241227.0.x86_64.qcow2"
  type         = "OS"
  format       = "qcow2"
}

resource "opennebula_virtual_machine" "almalinux_kitten_10_raw_validate_test_vm" {
  name        = "almalinux_kitten_10_raw_validate_test_vm"
  description = "AlmaLinux OS Kitten 10 VM with without raw data validation"
  cpu         = 2
  vcpu        = 2
  memory      = 2048
  context = {
    DEV_PREFIX     = "sd"
    NETWORK        = "YES"
    SET_HOSTNAME   = "$NAME"
    USERNAME       = "almalinux"
    SSH_PUBLIC_KEY = "$USER[SSH_PUBLIC_KEY]"
  }

  disk {
    image_id = opennebula_image.almalinux_kitten_10_x86_64.id
  }

  nic {
    network_id = var.network_id
  }

  template_section {
    name = "OS"
    elements = {
      MACHINE = "q35"
    }
  }

  template_section {
    name = "CPU_MODEL"
    elements = {
      MODEL = "host-passthrough"
    }
  }

  template_section {
    name = "FEATURES"
    elements = {
      ACPI        = "yes"
      APIC        = "yes"
      GUEST_AGENT = "yes"
    }
  }

  raw {
    type     = "kvm"
    validate = "no"
    data     = "<os firmware='efi'><firmware><feature enabled='yes' name='secure-boot'/><feature enabled='yes' name='enrolled-keys'/></firmware></os>"
  }
}

resource "opennebula_template" "almalinux_kitten_10_raw_validate_test_template" {
  name        = "almalinux_kitten_10_raw_validate_test_template"
  description = "AlmaLinux OS Kitten 10 VM Template without raw data validation"
  cpu         = 2
  vcpu        = 2
  memory      = 2048

  context = {
    DEV_PREFIX     = "sd"
    NETWORK        = "YES"
    SET_HOSTNAME   = "$NAME"
    USERNAME       = "almalinux"
    SSH_PUBLIC_KEY = "$USER[SSH_PUBLIC_KEY]"
  }

  disk {
    image_id = opennebula_image.almalinux_kitten_10_x86_64.id
  }

  features {
    acpi        = "YES"
    apic        = "YES"
    guest_agent = "YES"
  }

  cpumodel {
    model = "host-passthrough"
  }

  nic {
    network_id = var.network_id
  }

  raw {
    type     = "kvm"
    validate = "no"
    data     = "<os firmware='efi'><firmware><feature enabled='yes' name='secure-boot'/><feature enabled='yes' name='enrolled-keys'/></firmware></os>"
  }
}

resource "opennebula_virtual_machine" "almalinux_kitten_10_raw_validate_test_vm_from_template" {
  name        = "almalinux_kitten_10_raw_validate_test_vm_from_template"
  description = "AlmaLinux OS Kitten 10 VM with without raw data validation created from a VM Template"
  template_id = opennebula_template.almalinux_kitten_10_raw_validate_test_template.id
}

References

No response

LKHN added a commit to LKHN/terraform-provider-opennebula that referenced this issue Dec 30, 2024
Add support for validate argument the raw parameters of the resources:
- opennebula_template
- opennebula_virtual_machine

fixes OpenNebula#583

Signed-off-by: Elkhan Mammadli <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant