Skip to content

Commit dc6baf1

Browse files
authored
PLT-1997: Added boot-loader support in virtual machine resource (#704)
* PLT-1997: Added bootloader support in virtual machine resource * fix for firmware schema * added feature support * removed unwanted confusing schema defnition * unit test fix
1 parent b6d1480 commit dc6baf1

File tree

8 files changed

+505
-309
lines changed

8 files changed

+505
-309
lines changed

docs/resources/virtual_machine.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,8 @@ resource "spectrocloud_virtual_machine" "tf-test-vm-all-option-template-spec" {
522522
- `disk` (Block List) Disks describes disks, cdroms, floppy and luns which are connected to the vmi. (see [below for nested schema](#nestedblock--disk))
523523
- `dns_policy` (String) DNSPolicy defines how a pod's DNS will be configured.
524524
- `eviction_strategy` (String) EvictionStrategy can be set to "LiveMigrate" if the VirtualMachineInstance should be migrated instead of shut-off in case of a node drain.
525+
- `features` (Block List, Max: 1) Features allows to configure various virtualization features. (see [below for nested schema](#nestedblock--features))
526+
- `firmware` (Block List, Max: 1) Firmware configuration for the virtual machine. (see [below for nested schema](#nestedblock--firmware))
525527
- `generate_name` (String) Prefix, used by the server, to generate a unique name ONLY IF the `name` field has not been provided. This value will also be combined with a unique suffix. Read more: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#idempotency
526528
- `hostname` (String) Specifies the hostname of the vmi.
527529
- `interface` (Block List) Interfaces describe network interfaces which are added to the vmi. (see [below for nested schema](#nestedblock--interface))
@@ -996,6 +998,76 @@ Optional:
996998

997999

9981000

1001+
<a id="nestedblock--features"></a>
1002+
### Nested Schema for `features`
1003+
1004+
Optional:
1005+
1006+
- `acpi` (Block List, Max: 1) ACPI enables/disables ACPI inside the guest. Defaults to enabled. (see [below for nested schema](#nestedblock--features--acpi))
1007+
- `apic` (Block List, Max: 1) APIC enables/disables APIC inside the guest. Defaults to enabled. (see [below for nested schema](#nestedblock--features--apic))
1008+
- `smm` (Block List, Max: 1) SMM enables/disables System Management Mode. Required for Secure Boot with EFI. (see [below for nested schema](#nestedblock--features--smm))
1009+
1010+
<a id="nestedblock--features--acpi"></a>
1011+
### Nested Schema for `features.acpi`
1012+
1013+
Optional:
1014+
1015+
- `enabled` (Boolean) Enabled determines if the feature should be enabled or disabled on the guest. Defaults to true.
1016+
1017+
1018+
<a id="nestedblock--features--apic"></a>
1019+
### Nested Schema for `features.apic`
1020+
1021+
Optional:
1022+
1023+
- `enabled` (Boolean) Enabled determines if the feature should be enabled or disabled on the guest. Defaults to true.
1024+
1025+
1026+
<a id="nestedblock--features--smm"></a>
1027+
### Nested Schema for `features.smm`
1028+
1029+
Optional:
1030+
1031+
- `enabled` (Boolean) Enabled determines if the feature should be enabled or disabled on the guest.
1032+
1033+
1034+
1035+
<a id="nestedblock--firmware"></a>
1036+
### Nested Schema for `firmware`
1037+
1038+
Optional:
1039+
1040+
- `bootloader` (Block List, Max: 1) Settings to control the bootloader that is used. (see [below for nested schema](#nestedblock--firmware--bootloader))
1041+
- `serial` (String) The system-serial-number in SMBIOS.
1042+
- `uuid` (String) UUID reported by the vmi bios. Defaults to a random generated uid.
1043+
1044+
<a id="nestedblock--firmware--bootloader"></a>
1045+
### Nested Schema for `firmware.bootloader`
1046+
1047+
Optional:
1048+
1049+
- `bios` (Block List, Max: 1) If set (default), BIOS will be used. (see [below for nested schema](#nestedblock--firmware--bootloader--bios))
1050+
- `efi` (Block List, Max: 1) If set, EFI will be used instead of BIOS. (see [below for nested schema](#nestedblock--firmware--bootloader--efi))
1051+
1052+
<a id="nestedblock--firmware--bootloader--bios"></a>
1053+
### Nested Schema for `firmware.bootloader.bios`
1054+
1055+
Optional:
1056+
1057+
- `use_serial` (Boolean) If set, the BIOS output will be transmitted over serial.
1058+
1059+
1060+
<a id="nestedblock--firmware--bootloader--efi"></a>
1061+
### Nested Schema for `firmware.bootloader.efi`
1062+
1063+
Optional:
1064+
1065+
- `persistent` (Boolean) If set to true, Persistent will persist the EFI NVRAM across reboots. Defaults to false.
1066+
- `secure_boot` (Boolean) If set, SecureBoot will be enabled and the OVMF roms will be swapped for SecureBoot-enabled ones. Requires SMM to be enabled. Defaults to true.
1067+
1068+
1069+
1070+
9991071
<a id="nestedblock--interface"></a>
10001072
### Nested Schema for `interface`
10011073

spectrocloud/kubevirt/schema/virtualmachine/spec.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ func FlattenVMMToSpectroSchema(in kubevirtapiv1.VirtualMachineSpec, resourceData
6767
resource := vmDomain["resources"]
6868
cpu := vmDomain["cpu"]
6969
memory := vmDomain["memory"]
70+
firmware := vmDomain["firmware"]
71+
features := vmDomain["features"]
7072
device := vmDomain["devices"].([]interface{})[0].(map[string]interface{})
7173
disks := device["disk"]
7274
interfaces := device["interface"]
@@ -109,6 +111,12 @@ func FlattenVMMToSpectroSchema(in kubevirtapiv1.VirtualMachineSpec, resourceData
109111
if err := resourceData.Set("memory", memory); err != nil {
110112
return err
111113
}
114+
if err := resourceData.Set("firmware", firmware); err != nil {
115+
return err
116+
}
117+
if err := resourceData.Set("features", features); err != nil {
118+
return err
119+
}
112120
if err := resourceData.Set("resources", resource); err != nil {
113121
return err
114122
}

spectrocloud/kubevirt/schema/virtualmachine/virtual_machine.go

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,129 @@ func VirtualMachineFields() map[string]*schema.Schema {
281281
},
282282
},
283283
},
284+
"firmware": {
285+
Type: schema.TypeList,
286+
Description: "Firmware configuration for the virtual machine.",
287+
MaxItems: 1,
288+
Optional: true,
289+
Elem: &schema.Resource{
290+
Schema: map[string]*schema.Schema{
291+
"uuid": {
292+
Type: schema.TypeString,
293+
Description: "UUID reported by the vmi bios. Defaults to a random generated uid.",
294+
Optional: true,
295+
Computed: true,
296+
},
297+
"serial": {
298+
Type: schema.TypeString,
299+
Description: "The system-serial-number in SMBIOS.",
300+
Optional: true,
301+
},
302+
"bootloader": {
303+
Type: schema.TypeList,
304+
Description: "Settings to control the bootloader that is used.",
305+
MaxItems: 1,
306+
Optional: true,
307+
Elem: &schema.Resource{
308+
Schema: map[string]*schema.Schema{
309+
"bios": {
310+
Type: schema.TypeList,
311+
Description: "If set (default), BIOS will be used.",
312+
MaxItems: 1,
313+
Optional: true,
314+
Elem: &schema.Resource{
315+
Schema: map[string]*schema.Schema{
316+
"use_serial": {
317+
Type: schema.TypeBool,
318+
Description: "If set, the BIOS output will be transmitted over serial.",
319+
Optional: true,
320+
},
321+
},
322+
},
323+
},
324+
"efi": {
325+
Type: schema.TypeList,
326+
Description: "If set, EFI will be used instead of BIOS.",
327+
MaxItems: 1,
328+
Optional: true,
329+
Elem: &schema.Resource{
330+
Schema: map[string]*schema.Schema{
331+
"secure_boot": {
332+
Type: schema.TypeBool,
333+
Description: "If set, SecureBoot will be enabled and the OVMF roms will be swapped for SecureBoot-enabled ones. Requires SMM to be enabled. Defaults to true.",
334+
Optional: true,
335+
},
336+
"persistent": {
337+
Type: schema.TypeBool,
338+
Description: "If set to true, Persistent will persist the EFI NVRAM across reboots. Defaults to false.",
339+
Optional: true,
340+
},
341+
},
342+
},
343+
},
344+
},
345+
},
346+
},
347+
},
348+
},
349+
},
350+
"features": {
351+
Type: schema.TypeList,
352+
Description: "Features allows to configure various virtualization features.",
353+
MaxItems: 1,
354+
Optional: true,
355+
Elem: &schema.Resource{
356+
Schema: map[string]*schema.Schema{
357+
"acpi": {
358+
Type: schema.TypeList,
359+
Description: "ACPI enables/disables ACPI inside the guest. Defaults to enabled.",
360+
MaxItems: 1,
361+
Optional: true,
362+
Elem: &schema.Resource{
363+
Schema: map[string]*schema.Schema{
364+
"enabled": {
365+
Type: schema.TypeBool,
366+
Description: "Enabled determines if the feature should be enabled or disabled on the guest. Defaults to true.",
367+
Optional: true,
368+
Default: true,
369+
},
370+
},
371+
},
372+
},
373+
"apic": {
374+
Type: schema.TypeList,
375+
Description: "APIC enables/disables APIC inside the guest. Defaults to enabled.",
376+
MaxItems: 1,
377+
Optional: true,
378+
Elem: &schema.Resource{
379+
Schema: map[string]*schema.Schema{
380+
"enabled": {
381+
Type: schema.TypeBool,
382+
Description: "Enabled determines if the feature should be enabled or disabled on the guest. Defaults to true.",
383+
Optional: true,
384+
Default: true,
385+
},
386+
},
387+
},
388+
},
389+
"smm": {
390+
Type: schema.TypeList,
391+
Description: "SMM enables/disables System Management Mode. Required for Secure Boot with EFI.",
392+
MaxItems: 1,
393+
Optional: true,
394+
Elem: &schema.Resource{
395+
Schema: map[string]*schema.Schema{
396+
"enabled": {
397+
Type: schema.TypeBool,
398+
Description: "Enabled determines if the feature should be enabled or disabled on the guest.",
399+
Optional: true,
400+
},
401+
},
402+
},
403+
},
404+
},
405+
},
406+
},
284407
"network": virtualmachineinstance.NetworksSchema(),
285408
"volume": virtualmachineinstance.VolumesSchema(),
286409
"priority_class_name": {

0 commit comments

Comments
 (0)