@@ -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
3435func 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}
0 commit comments