From 17e45e1d7aad367d026dc41dd1dbc6b54c676784 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Philippe=20Four=C3=A8s?= Date: Fri, 8 Nov 2024 10:34:42 +0100 Subject: [PATCH 1/3] F-558: Add missing paramters in OS section of VM template This commit adds support for missing OS section in VM template. It aligns the OS section with the Documentation: https://docs.opennebula.io/6.10/management_and_operations/references/template.html?highlight=firmware#os-and-boot-options-section A correct fix consist in updating GOCA OSVec structure to reflec the Documentation A dedicated issue has bee openned in the Goca Repo: https://github.com/OpenNebula/one/issues/6782 Closes: F-558 --- ...esource_opennebula_virtual_machine_test.go | 91 ++++++++++++++++++- opennebula/shared_schemas.go | 54 ++++++++++- 2 files changed, 143 insertions(+), 2 deletions(-) diff --git a/opennebula/resource_opennebula_virtual_machine_test.go b/opennebula/resource_opennebula_virtual_machine_test.go index a37035aed..bef4649ba 100644 --- a/opennebula/resource_opennebula_virtual_machine_test.go +++ b/opennebula/resource_opennebula_virtual_machine_test.go @@ -66,6 +66,50 @@ func TestAccVirtualMachine(t *testing.T) { }), ), }, + { + Config: testAccVirtualMachineTemplateConfigOs, + Check: resource.ComposeTestCheckFunc( + testAccSetDSdummy(), + resource.TestCheckResourceAttr("opennebula_virtual_machine.testos", "name", "test-virtual_machine"), + resource.TestCheckResourceAttr("opennebula_virtual_machine.testos", "permissions", "642"), + resource.TestCheckResourceAttr("opennebula_virtual_machine.testos", "memory", "128"), + resource.TestCheckResourceAttr("opennebula_virtual_machine.testos", "cpu", "0.1"), + resource.TestCheckResourceAttr("opennebula_virtual_machine.testos", "context.%", "3"), + resource.TestCheckResourceAttr("opennebula_virtual_machine.testos", "context.NETWORK", "YES"), + resource.TestCheckResourceAttr("opennebula_virtual_machine.testos", "context.TESTVAR", "TEST"), + resource.TestCheckResourceAttr("opennebula_virtual_machine.testos", "graphics.#", "1"), + resource.TestCheckResourceAttr("opennebula_virtual_machine.testos", "graphics.0.keymap", "en-us"), + resource.TestCheckResourceAttr("opennebula_virtual_machine.testos", "graphics.0.listen", "0.0.0.0"), + resource.TestCheckResourceAttr("opennebula_virtual_machine.testos", "graphics.0.type", "VNC"), + resource.TestCheckResourceAttr("opennebula_virtual_machine.testos", "os.#", "1"), + resource.TestCheckResourceAttr("opennebula_virtual_machine.testos", "os.0.arch", "x86_64"), + resource.TestCheckResourceAttr("opennebula_virtual_machine.testos", "os.0.boot", ""), + resource.TestCheckResourceAttr("opennebula_virtual_machine.testos", "os.0.firmware", ""), + resource.TestCheckResourceAttr("opennebula_virtual_machine.testos", "os.0.firmware_secure", "false"), + resource.TestCheckResourceAttr("opennebula_virtual_machine.testos", "disk.#", "0"), + resource.TestCheckResourceAttr("opennebula_virtual_machine.testos", "tags.%", "2"), + resource.TestCheckResourceAttr("opennebula_virtual_machine.testos", "tags.env", "prod"), + resource.TestCheckResourceAttr("opennebula_virtual_machine.testos", "tags.customer", "test"), + resource.TestCheckResourceAttr("opennebula_virtual_machine.testos", "description", "VM created for provider acceptance tests"), + resource.TestCheckResourceAttr("opennebula_virtual_machine.testos", "timeout", "5"), + resource.TestCheckResourceAttrSet("opennebula_virtual_machine.testos", "uid"), + resource.TestCheckResourceAttrSet("opennebula_virtual_machine.testos", "gid"), + resource.TestCheckResourceAttrSet("opennebula_virtual_machine.testos", "uname"), + resource.TestCheckResourceAttrSet("opennebula_virtual_machine.testos", "gname"), + testAccCheckVirtualMachinePermissions(&shared.Permissions{ + OwnerU: 1, + OwnerM: 1, + GroupU: 1, + OtherM: 1, + }), + resource.TestCheckTypeSetElemNestedAttrs("opennebula_virtual_machine.testos", "template_section.*", map[string]string{ + "name": "test_vec_key", + "elements.%": "2", + "elements.testkey1": "testvalue1", + "elements.testkey2": "testvalue2", + }), + ), + }, { Config: testAccVirtualMachineConfigUpdate, Check: resource.ComposeTestCheckFunc( @@ -635,7 +679,7 @@ resource "opennebula_virtual_machine" "test" { os { arch = "x86_64" boot = "" - } + } tags = { env = "prod" @@ -656,6 +700,51 @@ resource "opennebula_virtual_machine" "test" { } ` +var testAccVirtualMachineTemplateConfigOs = ` +resource "opennebula_virtual_machine" "testos" { + name = "test-virtual_machine" + group = "oneadmin" + permissions = "642" + memory = 128 + cpu = 0.1 + description = "VM created for provider acceptance tests" + + context = { + TESTVAR = "TEST" + NETWORK = "YES" + SET_HOSTNAME = "$NAME" + } + + graphics { + type = "VNC" + listen = "0.0.0.0" + keymap = "en-us" + } + + os { + arch = "x86_64" + boot = "" + firmware = "" + firmware_secure = false + } + + tags = { + env = "prod" + customer = "test" + } + + template_section { + name = "test_vec_key" + elements = { + testkey1 = "testvalue1" + testkey2 = "testvalue2" + } + } + + timeout = 5 +} +` + var testAccVirtualMachineTemplateConfigCPUModel = ` resource "opennebula_virtual_machine" "test" { name = "test-virtual_machine-renamed" diff --git a/opennebula/shared_schemas.go b/opennebula/shared_schemas.go index 24bb0eb75..08f16c699 100644 --- a/opennebula/shared_schemas.go +++ b/opennebula/shared_schemas.go @@ -414,7 +414,7 @@ func osSchema() *schema.Schema { Type: schema.TypeList, Optional: true, MaxItems: 1, - Description: "Definition of OS boot and type for the Virtual Machine", + Description: "Definition of OS parameters for the Virtual Machine", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "arch": { @@ -425,6 +425,58 @@ func osSchema() *schema.Schema { Type: schema.TypeString, Required: true, }, + "machine": { + Type: schema.TypeString, + Optional: true, + }, + "kernel": { + Type: schema.TypeString, + Optional: true, + ConflictsWith: []string{"os.0.kernel_ds"}, + }, + "kernel_ds": { + Type: schema.TypeString, + Optional: true, + ConflictsWith: []string{"os.0.kernel"}, + }, + "initrd": { + Type: schema.TypeString, + Optional: true, + ConflictsWith: []string{"os.0.initrd_ds"}, + }, + "initrd_ds": { + Type: schema.TypeString, + Optional: true, + ConflictsWith: []string{"os.0.initrd"}, + }, + "root": { + Type: schema.TypeString, + Optional: true, + }, + "kernel_cmd": { + Type: schema.TypeString, + Optional: true, + }, + "bootloader": { + Type: schema.TypeString, + Optional: true, + }, + "sd_disk_bus": { + Type: schema.TypeString, + Optional: true, + }, + "uuid": { + Type: schema.TypeString, + Optional: true, + }, + "firmware": { + Type: schema.TypeString, + Optional: true, + }, + "firmware_secure": { + Type: schema.TypeBool, + Optional: true, + }, }, }, } From 862fc01eafbd13125167b21947cb9527e93349f4 Mon Sep 17 00:00:00 2001 From: Jaime Date: Mon, 18 Nov 2024 15:15:51 +0100 Subject: [PATCH 2/3] F #558: Add usage of new OS params in VM template [skip ci] Signed-off-by: Jaime --- opennebula/shared_schemas.go | 46 ++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/opennebula/shared_schemas.go b/opennebula/shared_schemas.go index 08f16c699..7a2f5fccb 100644 --- a/opennebula/shared_schemas.go +++ b/opennebula/shared_schemas.go @@ -468,6 +468,7 @@ func osSchema() *schema.Schema { "uuid": { Type: schema.TypeString, Optional: true, + Computed: true, }, "firmware": { Type: schema.TypeString, @@ -674,7 +675,19 @@ func addOS(tpl *vm.Template, os []interface{}) { if os[i] != nil { osconfig := os[i].(map[string]interface{}) tpl.AddOS(vmk.Arch, osconfig["arch"].(string)) + tpl.AddOS(vmk.Machine, osconfig["machine"].(string)) + tpl.AddOS(vmk.Kernel, osconfig["kernel"].(string)) + tpl.AddOS(vmk.KernelDS, osconfig["kernel_ds"].(string)) + tpl.AddOS(vmk.Initrd, osconfig["initrd"].(string)) + tpl.AddOS(vmk.InitrdDS, osconfig["initrd_ds"].(string)) + tpl.AddOS(vmk.Root, osconfig["root"].(string)) + tpl.AddOS(vmk.KernelCmd, osconfig["kernel_cmd"].(string)) + tpl.AddOS(vmk.Bootloader, osconfig["bootloader"].(string)) tpl.AddOS(vmk.Boot, osconfig["boot"].(string)) + tpl.AddOS(vmk.SDDiskBus, osconfig["sd_disk_bus"].(string)) + tpl.AddOS(vmk.UUID, osconfig["uuid"].(string)) + tpl.AddOS(vmk.Firmware, osconfig["firmware"].(string)) + tpl.AddOS(vmk.FirmwareSecure, osconfig["firmware_secure"].(bool)) } } @@ -1012,7 +1025,19 @@ func flattenTemplate(d *schema.ResourceData, inheritedVectors map[string]interfa // OS osMap := make([]map[string]interface{}, 0, 1) arch, _ := vmTemplate.GetOS(vmk.Arch) + machine, _ := vmTemplate.GetOS(vmk.Machine) + kernel, _ := vmTemplate.GetOS(vmk.Kernel) + kernelDS, _ := vmTemplate.GetOS(vmk.KernelDS) + initrd, _ := vmTemplate.GetOS(vmk.Initrd) + initrdDS, _ := vmTemplate.GetOS(vmk.InitrdDS) + root, _ := vmTemplate.GetOS(vmk.Root) + kernelCmd, _ := vmTemplate.GetOS(vmk.KernelCmd) + bootloader, _ := vmTemplate.GetOS(vmk.Bootloader) boot, _ := vmTemplate.GetOS(vmk.Boot) + sdDiskBus, _ := vmTemplate.GetOS(vmk.SDDiskBus) + uuid, _ := vmTemplate.GetOS(vmk.UUID) + firmware, _ := vmTemplate.GetOS(vmk.Firmware) + firmwareSecure, firmwareSecureErr := vmTemplate.GetOS(vmk.FirmwareSecure) // CPU Model cpumodelMap := make([]map[string]interface{}, 0, 1) cpumodel, _ := vmTemplate.GetCPUModel(vmk.Model) @@ -1069,9 +1094,26 @@ func flattenTemplate(d *schema.ResourceData, inheritedVectors map[string]interfa // Set OS to resource if arch != "" { + firmwareSecureBool := false + if firmwareSecureErr == nil && firmwareSecure == "true" { + firmwareSecureBool = true + } + osMap = append(osMap, map[string]interface{}{ - "arch": arch, - "boot": boot, + "arch": arch, + "machine": machine, + "kernel": kernel, + "kernel_ds": kernelDS, + "initrd": initrd, + "initrd_ds": initrdDS, + "root": root, + "kernel_cmd": kernelCmd, + "bootloader": bootloader, + "boot": boot, + "sd_disk_bus": sdDiskBus, + "uuid": uuid, + "firmware": firmware, + "firmware_secure": firmwareSecureBool, }) _, inherited := inheritedVectors["OS"] if !inherited { From e58cbc42987831d855eefaae1bd68ea7d2a499e1 Mon Sep 17 00:00:00 2001 From: Jaime Date: Thu, 21 Nov 2024 10:17:24 +0100 Subject: [PATCH 3/3] F #558: Update docs and goca version with new OSVec Signed-off-by: Jaime --- CHANGELOG.md | 6 ++++++ go.mod | 2 +- go.sum | 4 ++-- website/docs/r/template.html.markdown | 13 +++++++++++++ website/docs/r/virtual_machine.html.markdown | 13 +++++++++++++ website/docs/r/virtual_router_instance.markdown | 13 +++++++++++++ .../r/virtual_router_instance_template.markdown | 13 +++++++++++++ 7 files changed, 61 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9db225434..4bb9fafa6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# 1.5.0 (Unreleased) + +FEATURES: + +* shared_schemas: Add `machine`, `kernel`, `kernel_ds`, `initrd`, `initrd_ds`, `root`, `kernel_cmd`, `bootloader`, `sd_disk_bus`, `uuid`, `firmware` and `firmware_secure` to OS schema (#558) + # 1.4.1 (October 22nd, 2024) FEATURES: diff --git a/go.mod b/go.mod index 820b12505..ac26264b2 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/OpenNebula/terraform-provider-opennebula go 1.18 require ( - github.com/OpenNebula/one/src/oca/go/src/goca v0.0.0-20240528115224-c53e48565a10 + github.com/OpenNebula/one/src/oca/go/src/goca v0.0.0-20241120172129-bb65c2242412 github.com/hashicorp/go-uuid v1.0.3 github.com/hashicorp/go-version v1.6.0 github.com/hashicorp/terraform-plugin-sdk/v2 v2.24.1 diff --git a/go.sum b/go.sum index 3cf22403c..d15dbfd7d 100644 --- a/go.sum +++ b/go.sum @@ -2,8 +2,8 @@ cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA= github.com/Microsoft/go-winio v0.4.16 h1:FtSW/jqD+l4ba5iPBj9CODVtgfYAD8w2wS923g/cFDk= github.com/Microsoft/go-winio v0.4.16/go.mod h1:XB6nPKklQyQ7GC9LdcBEcBl8PF76WugXOPRXwdLnMv0= -github.com/OpenNebula/one/src/oca/go/src/goca v0.0.0-20240528115224-c53e48565a10 h1:g++kihIwzRFwxAV6fQzvwsEP6/l9ej8G/tixWaNBc1M= -github.com/OpenNebula/one/src/oca/go/src/goca v0.0.0-20240528115224-c53e48565a10/go.mod h1:dvAwZi1Aol7eu6BENzHtl8ztGBkacB9t/fJj+fYk+Xg= +github.com/OpenNebula/one/src/oca/go/src/goca v0.0.0-20241120172129-bb65c2242412 h1:CUdtKmQcq03A3ludh8AMp+g2NpUdizZU7E7fuuzLzo8= +github.com/OpenNebula/one/src/oca/go/src/goca v0.0.0-20241120172129-bb65c2242412/go.mod h1:dvAwZi1Aol7eu6BENzHtl8ztGBkacB9t/fJj+fYk+Xg= github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7 h1:YoJbenK9C67SkzkDfmQuVln04ygHj3vjZfd9FL+GmQQ= github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7/go.mod h1:z4/9nQmJSSwwds7ejkxaJwO37dru3geImFUdJlaLzQo= github.com/acomagu/bufpipe v1.0.3 h1:fxAGrHZTgQ9w5QqVItgzwj235/uYZYgbXitB+dLupOk= diff --git a/website/docs/r/template.html.markdown b/website/docs/r/template.html.markdown index 3500ced7c..828da8349 100644 --- a/website/docs/r/template.html.markdown +++ b/website/docs/r/template.html.markdown @@ -128,6 +128,19 @@ The following arguments are supported: * `arch` - (Required) Hardware architecture of the Virtual machine. Must fit the host architecture. * `boot` - (Optional) `OS` disk to use to boot on. +* `machine` - (Optional) libvirt machine type. +* `kernel` - (Optional) Path to the `OS` kernel to boot the image in the host. +* `kernel_ds` - (Optional) Image to be used as kernel. (see !!) +* `initrd` - (Optional) Path to the initrd image in the host. +* `initrd_ds` - (Optional) Image to be used as ramdisk. (see !!) +* `root` - (Optional) Device to be mounted as root. +* `kernel_cmd` - (Optional) Arguments for the booting kernel. +* `bootloader` - (Optional) Path to the bootloader executable. +* `sd_disk_bus` - (Optional) Bus for disks with sd prefix, either `scsi` or `sata`, if attribute is missing, libvirt chooses itself. +* `uuid` - (Optional) Unique ID of the VM. +* `firmware` - (Optional) Firmware type or firmware path. Possible values: `BIOS` or path for KVM, `BIOS` or `UEFI` for vCenter. +* `firmware_secure` - (Optional) Enable Secure Boot. (Can be `true` or `false`). +* (!!) Use one of `kernel_ds` or `kernel` (and `initrd` or `initrd_ds`). ### Features parameters diff --git a/website/docs/r/virtual_machine.html.markdown b/website/docs/r/virtual_machine.html.markdown index 0b78586ca..6872ad629 100644 --- a/website/docs/r/virtual_machine.html.markdown +++ b/website/docs/r/virtual_machine.html.markdown @@ -129,6 +129,19 @@ The following arguments are supported: * `arch` - (Required) Hardware architecture of the Virtual machine. Must fit the host architecture. * `boot` - (Optional) `OS` disk to use to boot on. +* `machine` - (Optional) libvirt machine type. +* `kernel` - (Optional) Path to the `OS` kernel to boot the image in the host. +* `kernel_ds` - (Optional) Image to be used as kernel. (see !!) +* `initrd` - (Optional) Path to the initrd image in the host. +* `initrd_ds` - (Optional) Image to be used as ramdisk. (see !!) +* `root` - (Optional) Device to be mounted as root. +* `kernel_cmd` - (Optional) Arguments for the booting kernel. +* `bootloader` - (Optional) Path to the bootloader executable. +* `sd_disk_bus` - (Optional) Bus for disks with sd prefix, either `scsi` or `sata`, if attribute is missing, libvirt chooses itself. +* `uuid` - (Optional) Unique ID of the VM. +* `firmware` - (Optional) Firmware type or firmware path. Possible values: `BIOS` or path for KVM, `BIOS` or `UEFI` for vCenter. +* `firmware_secure` - (Optional) Enable Secure Boot. (Can be `true` or `false`). +* (!!) Use one of `kernel_ds` or `kernel` (and `initrd` or `initrd_ds`). ### Disk parameters diff --git a/website/docs/r/virtual_router_instance.markdown b/website/docs/r/virtual_router_instance.markdown index 65751fe7c..32bdbe420 100644 --- a/website/docs/r/virtual_router_instance.markdown +++ b/website/docs/r/virtual_router_instance.markdown @@ -118,6 +118,19 @@ The following arguments are supported: * `arch` - (Required) Hardware architecture of the virtual router instance. Must fit the host architecture. * `boot` - (Optional) `OS` disk to use to boot on. +* `machine` - (Optional) libvirt machine type. +* `kernel` - (Optional) Path to the `OS` kernel to boot the image in the host. +* `kernel_ds` - (Optional) Image to be used as kernel. (see !!) +* `initrd` - (Optional) Path to the initrd image in the host. +* `initrd_ds` - (Optional) Image to be used as ramdisk. (see !!) +* `root` - (Optional) Device to be mounted as root. +* `kernel_cmd` - (Optional) Arguments for the booting kernel. +* `bootloader` - (Optional) Path to the bootloader executable. +* `sd_disk_bus` - (Optional) Bus for disks with sd prefix, either `scsi` or `sata`, if attribute is missing, libvirt chooses itself. +* `uuid` - (Optional) Unique ID of the VM. +* `firmware` - (Optional) Firmware type or firmware path. Possible values: `BIOS` or path for KVM, `BIOS` or `UEFI` for vCenter. +* `firmware_secure` - (Optional) Enable Secure Boot. (Can be `true` or `false`). +* (!!) Use one of `kernel_ds` or `kernel` (and `initrd` or `initrd_ds`). ### Disk parameters diff --git a/website/docs/r/virtual_router_instance_template.markdown b/website/docs/r/virtual_router_instance_template.markdown index cd1f0b11e..d6d8663fa 100644 --- a/website/docs/r/virtual_router_instance_template.markdown +++ b/website/docs/r/virtual_router_instance_template.markdown @@ -88,6 +88,19 @@ resource "opennebula_virtual_router_instance_template" "example" { * `arch` - (Required) Hardware architecture of the Virtual machine. Must fit the host architecture. * `boot` - (Optional) `OS` disk to use to boot on. +* `machine` - (Optional) libvirt machine type. +* `kernel` - (Optional) Path to the `OS` kernel to boot the image in the host. +* `kernel_ds` - (Optional) Image to be used as kernel. (see !!) +* `initrd` - (Optional) Path to the initrd image in the host. +* `initrd_ds` - (Optional) Image to be used as ramdisk. (see !!) +* `root` - (Optional) Device to be mounted as root. +* `kernel_cmd` - (Optional) Arguments for the booting kernel. +* `bootloader` - (Optional) Path to the bootloader executable. +* `sd_disk_bus` - (Optional) Bus for disks with sd prefix, either `scsi` or `sata`, if attribute is missing, libvirt chooses itself. +* `uuid` - (Optional) Unique ID of the VM. +* `firmware` - (Optional) Firmware type or firmware path. Possible values: `BIOS` or path for KVM, `BIOS` or `UEFI` for vCenter. +* `firmware_secure` - (Optional) Enable Secure Boot. (Can be `true` or `false`). +* (!!) Use one of `kernel_ds` or `kernel` (and `initrd` or `initrd_ds`). ### Features parameters