Skip to content
Merged
Changes from 2 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
22 changes: 21 additions & 1 deletion cloudstack/resource_cloudstack_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (

"github.com/apache/cloudstack-go/v2/cloudstack"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)

func resourceCloudStackInstance() *schema.Resource {
Expand Down Expand Up @@ -182,6 +183,13 @@ func resourceCloudStackInstance() *schema.Resource {
Default: false,
},

"boot_mode": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"Secure", "Legacy"}, true),
ForceNew: true,
},

"start_vm": {
Type: schema.TypeBool,
Optional: true,
Expand Down Expand Up @@ -262,6 +270,10 @@ func resourceCloudStackInstanceCreate(d *schema.ResourceData, meta interface{})
return e.Error()
}

if bootMode, hasBoot := d.GetOk("boot_mode"); hasBoot && !d.Get("uefi").(bool) {
return fmt.Errorf("boot_mode can only be specified when uefi is true, got boot_mode=%s with uefi=false", bootMode.(string))
}

// Create a new parameter struct
p := cs.VirtualMachine.NewDeployVirtualMachineParams(serviceofferingid, templateid, zone.Id)
p.SetStartvm(d.Get("start_vm").(bool))
Expand Down Expand Up @@ -331,7 +343,11 @@ func resourceCloudStackInstanceCreate(d *schema.ResourceData, meta interface{})

if d.Get("uefi").(bool) {
p.SetBoottype("UEFI")
p.SetBootmode("Legacy")
if bootmode, ok := d.GetOk("boot_mode"); ok {
p.SetBootmode(bootmode.(string))
} else {
p.SetBootmode("Legacy")
}
}

if zone.Networktype == "Advanced" {
Expand Down Expand Up @@ -538,6 +554,10 @@ func resourceCloudStackInstanceRead(d *schema.ResourceData, meta interface{}) er
setValueOrID(d, "template", vm.Templatename, vm.Templateid)
setValueOrID(d, "project", vm.Project, vm.Projectid)
setValueOrID(d, "zone", vm.Zonename, vm.Zoneid)
d.Set("uefi", strings.EqualFold(vm.Boottype, "UEFI"))
if strings.EqualFold(vm.Boottype, "UEFI") && vm.Bootmode != "" {
d.Set("boot_mode", vm.Bootmode)
}

return nil
}
Expand Down
Loading