Skip to content
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
FEATURES:

* provider: Added a `--debug` flag for enabling provider debugging (#582)
* 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)

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