@@ -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,13 @@ 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+ },
192+
185193 "start_vm" : {
186194 Type : schema .TypeBool ,
187195 Optional : true ,
@@ -262,6 +270,10 @@ func resourceCloudStackInstanceCreate(d *schema.ResourceData, meta interface{})
262270 return e .Error ()
263271 }
264272
273+ if bootMode , hasBoot := d .GetOk ("boot_mode" ); hasBoot && ! d .Get ("uefi" ).(bool ) {
274+ return fmt .Errorf ("boot_mode can only be specified when uefi is true, got boot_mode=%s with uefi=false" , bootMode .(string ))
275+ }
276+
265277 // Create a new parameter struct
266278 p := cs .VirtualMachine .NewDeployVirtualMachineParams (serviceofferingid , templateid , zone .Id )
267279 p .SetStartvm (d .Get ("start_vm" ).(bool ))
@@ -331,7 +343,11 @@ func resourceCloudStackInstanceCreate(d *schema.ResourceData, meta interface{})
331343
332344 if d .Get ("uefi" ).(bool ) {
333345 p .SetBoottype ("UEFI" )
334- p .SetBootmode ("Legacy" )
346+ if bootmode , ok := d .GetOk ("boot_mode" ); ok {
347+ p .SetBootmode (bootmode .(string ))
348+ } else {
349+ p .SetBootmode ("Legacy" )
350+ }
335351 }
336352
337353 if zone .Networktype == "Advanced" {
@@ -538,6 +554,10 @@ func resourceCloudStackInstanceRead(d *schema.ResourceData, meta interface{}) er
538554 setValueOrID (d , "template" , vm .Templatename , vm .Templateid )
539555 setValueOrID (d , "project" , vm .Project , vm .Projectid )
540556 setValueOrID (d , "zone" , vm .Zonename , vm .Zoneid )
557+ d .Set ("uefi" , vm .Boottype == "UEFI" )
558+ if vm .Boottype == "UEFI" && vm .Bootmode != "" {
559+ d .Set ("boot_mode" , vm .Bootmode )
560+ }
541561
542562 return nil
543563}
0 commit comments