Skip to content

Commit 47b2bbf

Browse files
authored
Add boot mode for instance (apache#251)
* Add support boot mode when UEFI true * case insensitive check * add description & update doc
1 parent 86fb0e4 commit 47b2bbf

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

cloudstack/resource_cloudstack_instance.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929

3030
"github.com/apache/cloudstack-go/v2/cloudstack"
3131
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
32+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
3233
)
3334

3435
func resourceCloudStackInstance() *schema.Resource {
@@ -182,6 +183,14 @@ func resourceCloudStackInstance() *schema.Resource {
182183
Default: false,
183184
},
184185

186+
"boot_mode": {
187+
Type: schema.TypeString,
188+
Optional: true,
189+
ValidateFunc: validation.StringInSlice([]string{"Secure", "Legacy"}, true),
190+
ForceNew: true,
191+
Description: "The boot mode of the instance. Can only be specified when uefi is true. Valid options are 'Legacy' and 'Secure'.",
192+
},
193+
185194
"start_vm": {
186195
Type: schema.TypeBool,
187196
Optional: true,
@@ -262,6 +271,10 @@ func resourceCloudStackInstanceCreate(d *schema.ResourceData, meta interface{})
262271
return e.Error()
263272
}
264273

274+
if bootMode, hasBoot := d.GetOk("boot_mode"); hasBoot && !d.Get("uefi").(bool) {
275+
return fmt.Errorf("boot_mode can only be specified when uefi is true, got boot_mode=%s with uefi=false", bootMode.(string))
276+
}
277+
265278
// Create a new parameter struct
266279
p := cs.VirtualMachine.NewDeployVirtualMachineParams(serviceofferingid, templateid, zone.Id)
267280
p.SetStartvm(d.Get("start_vm").(bool))
@@ -331,7 +344,11 @@ func resourceCloudStackInstanceCreate(d *schema.ResourceData, meta interface{})
331344

332345
if d.Get("uefi").(bool) {
333346
p.SetBoottype("UEFI")
334-
p.SetBootmode("Legacy")
347+
if bootmode, ok := d.GetOk("boot_mode"); ok {
348+
p.SetBootmode(bootmode.(string))
349+
} else {
350+
p.SetBootmode("Legacy")
351+
}
335352
}
336353

337354
if zone.Networktype == "Advanced" {
@@ -538,6 +555,10 @@ func resourceCloudStackInstanceRead(d *schema.ResourceData, meta interface{}) er
538555
setValueOrID(d, "template", vm.Templatename, vm.Templateid)
539556
setValueOrID(d, "project", vm.Project, vm.Projectid)
540557
setValueOrID(d, "zone", vm.Zonename, vm.Zoneid)
558+
d.Set("uefi", strings.EqualFold(vm.Boottype, "UEFI"))
559+
if strings.EqualFold(vm.Boottype, "UEFI") && vm.Bootmode != "" {
560+
d.Set("boot_mode", vm.Bootmode)
561+
}
541562

542563
return nil
543564
}

website/docs/r/instance.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ The following arguments are supported:
104104

105105
* `uefi` - (Optional) When set, will boot the instance in UEFI/Legacy mode (defaults false)
106106

107+
* `boot_mode` - (Optional) The boot mode of the instance. Can only be specified when uefi is true. Valid options are 'Legacy' and 'Secure'.
108+
107109
## Attributes Reference
108110

109111
The following attributes are exported:

0 commit comments

Comments
 (0)