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

F-558: Add missing paramters in OS section of VM template #579

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
91 changes: 90 additions & 1 deletion opennebula/resource_opennebula_virtual_machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -635,7 +679,7 @@ resource "opennebula_virtual_machine" "test" {
os {
arch = "x86_64"
boot = ""
}
}

tags = {
env = "prod"
Expand All @@ -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"
Expand Down
100 changes: 97 additions & 3 deletions opennebula/shared_schemas.go
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -425,6 +425,59 @@ 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,
Computed: true,
},
"firmware": {
Type: schema.TypeString,
Optional: true,
},
"firmware_secure": {
Type: schema.TypeBool,
Optional: true,
},
},
},
}
Expand Down Expand Up @@ -622,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))
}
}

Expand Down Expand Up @@ -960,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)
Expand Down Expand Up @@ -1017,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 {
Expand Down
13 changes: 13 additions & 0 deletions website/docs/r/template.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 13 additions & 0 deletions website/docs/r/virtual_machine.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 13 additions & 0 deletions website/docs/r/virtual_router_instance.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 13 additions & 0 deletions website/docs/r/virtual_router_instance_template.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading