Skip to content

Commit

Permalink
Implemented boot options update
Browse files Browse the repository at this point in the history
  • Loading branch information
pbesret committed Oct 24, 2023
1 parent 56298e8 commit 6b37ab5
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 61 deletions.
27 changes: 14 additions & 13 deletions docs/resources/compute_virtual_machine.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ resource "cloudtemple_compute_virtual_machine" "ubuntu-cloud-init" {
### Optional

- `backup_sla_policies` (Set of String) The IDs of the SLA policies to assign to the virtual machine.
- `boot_options` (Block List, Max: 1) (see [below for nested schema](#nestedblock--boot_options))
- `clone_virtual_machine_id` (String) The ID of the virtual machine to clone. Conflict with `content_library_item_id`.
- `cloud_init` (Map of String) A set of cloud-init compatible key/value used to configure the virtual machine.

Expand Down Expand Up @@ -254,7 +255,6 @@ resource "cloudtemple_compute_virtual_machine" "ubuntu-cloud-init" {

### Read-Only

- `boot_options` (List of Object) (see [below for nested schema](#nestedatt--boot_options))
- `consolidation_needed` (Boolean)
- `cpu_usage` (Number)
- `datastore_name` (String)
Expand All @@ -277,6 +277,19 @@ resource "cloudtemple_compute_virtual_machine" "ubuntu-cloud-init" {
- `tools_version` (Number)
- `triggered_alarms` (List of Object) (see [below for nested schema](#nestedatt--triggered_alarms))

<a id="nestedblock--boot_options"></a>
### Nested Schema for `boot_options`

Optional:

- `boot_delay` (Number) Delay in milliseconds before starting the boot sequence. The boot delay specifies a time interval between virtual machine power on or restart and the beginning of the boot sequence.
- `boot_retry_delay` (Number) Delay in milliseconds before a boot retry. The boot retry delay specifies a time interval between virtual machine boot failure and the subsequent attempt to boot again. The virtual machine uses this value only if bootRetryEnabled is true.
- `boot_retry_enabled` (Boolean) If set to true, a virtual machine that fails to boot will try again after the bootRetryDelay time period has expired. When false, the virtual machine waits indefinitely for you to initiate boot retry.
- `efi_secure_boot_enabled` (Boolean) If set to true, the virtual machine's firmware will perform signature checks of any EFI images loaded during startup, and will refuse to start any images which do not pass those signature checks.
- `enter_bios_setup` (Boolean) If set to true, the virtual machine automatically enters BIOS setup the next time it boots. The virtual machine resets this flag to false so that subsequent boots proceed normally.
- `firmware` (String) Firmware type. (BIOS or EFI)


<a id="nestedblock--os_disk"></a>
### Nested Schema for `os_disk`

Expand Down Expand Up @@ -319,18 +332,6 @@ Read-Only:
- `type` (String)


<a id="nestedatt--boot_options"></a>
### Nested Schema for `boot_options`

Read-Only:

- `boot_delay` (Number)
- `boot_retry_delay` (Number)
- `boot_retry_enabled` (Boolean)
- `enter_bios_setup` (Boolean)
- `firmware` (String)


<a id="nestedatt--extra_config"></a>
### Nested Schema for `extra_config`

Expand Down
22 changes: 12 additions & 10 deletions internal/client/compute_virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,21 @@ type VirtualMachineStorage struct {
}

type VirtualMachineBootOptions struct {
Firmware string `terraform:"firmware"`
BootDelay int `terraform:"boot_delay"`
EnterBIOSSetup bool `terraform:"enter_bios_setup"`
BootRetryEnabled bool `terraform:"boot_retry_enabled"`
BootRetryDelay int `terraform:"boot_retry_delay"`
Firmware string `terraform:"firmware"`
BootDelay int `terraform:"boot_delay"`
EnterBIOSSetup bool `terraform:"enter_bios_setup"`
BootRetryEnabled bool `terraform:"boot_retry_enabled"`
BootRetryDelay int `terraform:"boot_retry_delay"`
EFISecureBootEnabled bool `terraform:"efi_secure_boot_enabled"`
}

type BootOptions struct {
BootDelay int `json:"bootDelay"`
BootRetryDelay int `json:"bootRetryDelay"`
BootRetryEnabled bool `json:"bootRetryEnabled"`
EnterBIOSSetup bool `json:"enterBIOSSetup"`
Firmware string `json:"firmware"`
BootDelay int `json:"bootDelay"`
BootRetryDelay int `json:"bootRetryDelay"`
BootRetryEnabled bool `json:"bootRetryEnabled"`
EnterBIOSSetup bool `json:"enterBIOSSetup"`
Firmware string `json:"firmware"`
EFISecureBootEnabled bool `json:"efiSecureBootEnabled"`
}

type PowerRequest struct {
Expand Down
102 changes: 64 additions & 38 deletions internal/provider/resource_compute_virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,54 @@ Virtual machines can be created using three different methods:
},
},
},
"boot_options": {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Computed: true,

Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"firmware": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "Firmware type. (BIOS or EFI)",
},
"boot_delay": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "Delay in milliseconds before starting the boot sequence. The boot delay specifies a time interval between virtual machine power on or restart and the beginning of the boot sequence.",
},
"enter_bios_setup": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
Description: "If set to true, the virtual machine automatically enters BIOS setup the next time it boots. The virtual machine resets this flag to false so that subsequent boots proceed normally.",
},
"boot_retry_enabled": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
Description: "If set to true, a virtual machine that fails to boot will try again after the bootRetryDelay time period has expired. When false, the virtual machine waits indefinitely for you to initiate boot retry.",
},
"boot_retry_delay": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "Delay in milliseconds before a boot retry. The boot retry delay specifies a time interval between virtual machine boot failure and the subsequent attempt to boot again. The virtual machine uses this value only if bootRetryEnabled is true.",
},
"efi_secure_boot_enabled": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
Description: "If set to true, the virtual machine's firmware will perform signature checks of any EFI images loaded during startup, and will refuse to start any images which do not pass those signature checks.",
},
},
},
},

// Out
"moref": {
Type: schema.TypeString,
Expand Down Expand Up @@ -415,35 +463,6 @@ Virtual machines can be created using three different methods:
},
},
},
"boot_options": {
Type: schema.TypeList,
Computed: true,

Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"firmware": {
Type: schema.TypeString,
Computed: true,
},
"boot_delay": {
Type: schema.TypeInt,
Computed: true,
},
"enter_bios_setup": {
Type: schema.TypeBool,
Computed: true,
},
"boot_retry_enabled": {
Type: schema.TypeBool,
Computed: true,
},
"boot_retry_delay": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
"replication_config": {
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -825,22 +844,29 @@ func computeVirtualMachineUpdate(ctx context.Context, d *schema.ResourceData, me
func updateVirtualMachine(ctx context.Context, d *schema.ResourceData, meta any, updatePower bool) diag.Diagnostics {
c := getClient(meta)

activityId, err := c.Compute().VirtualMachine().Update(ctx, &client.UpdateVirtualMachineRequest{
req := &client.UpdateVirtualMachineRequest{
Id: d.Id(),
Ram: d.Get("memory").(int),
Cpu: d.Get("cpu").(int),
CorePerSocket: d.Get("num_cores_per_socket").(int),
HotCpuAdd: d.Get("cpu_hot_add_enabled").(bool),
HotCpuRemove: d.Get("cpu_hot_remove_enabled").(bool),
HotMemAdd: d.Get("memory_hot_add_enabled").(bool),
BootOptions: &client.BootOptions{
BootDelay: 0,
BootRetryDelay: 10000,
BootRetryEnabled: false,
EnterBIOSSetup: false,
Firmware: "bios",
},
})
}

if len(d.Get("boot_options").([]interface{})) > 0 {
bootOptions := d.Get("boot_options").([]interface{})[0]
req.BootOptions = &client.BootOptions{
BootDelay: bootOptions.(map[string]interface{})["boot_delay"].(int),
BootRetryDelay: bootOptions.(map[string]interface{})["boot_retry_delay"].(int),
BootRetryEnabled: bootOptions.(map[string]interface{})["boot_retry_enabled"].(bool),
EnterBIOSSetup: bootOptions.(map[string]interface{})["enter_bios_setup"].(bool),
Firmware: strings.ToLower(bootOptions.(map[string]interface{})["firmware"].(string)),
EFISecureBootEnabled: bootOptions.(map[string]interface{})["efi_secure_boot_enabled"].(bool),
}
}

activityId, err := c.Compute().VirtualMachine().Update(ctx, req)
if err != nil {
return diag.Errorf("failed to update virtual machine: %s", err)
}
Expand Down

0 comments on commit 6b37ab5

Please sign in to comment.