@@ -89,11 +89,20 @@ func resourceBmInstance() *schema.Resource {
89
89
},
90
90
"name" : & schema.Schema {
91
91
Type : schema .TypeString ,
92
- Required : true ,
92
+ Optional : true ,
93
+ Computed : true ,
94
+ ExactlyOneOf : []string {
95
+ "name" ,
96
+ "name_templates" ,
97
+ },
93
98
},
94
99
"name_templates" : & schema.Schema {
95
100
Type : schema .TypeString ,
96
101
Optional : true ,
102
+ ExactlyOneOf : []string {
103
+ "name" ,
104
+ "name_templates" ,
105
+ },
97
106
},
98
107
"image_id" : {
99
108
Type : schema .TypeString ,
@@ -293,7 +302,6 @@ func resourceBmInstanceCreate(ctx context.Context, d *schema.ResourceData, m int
293
302
log .Printf ("[DEBUG] Baremetal interfaces: %+v" , newInterface )
294
303
opts := bminstances.CreateOpts {
295
304
Flavor : d .Get ("flavor_id" ).(string ),
296
- Names : []string {d .Get ("name" ).(string )},
297
305
ImageID : d .Get ("image_id" ).(string ),
298
306
AppTemplateID : d .Get ("apptemplate_id" ).(string ),
299
307
Keypair : d .Get ("keypair_name" ).(string ),
@@ -304,6 +312,11 @@ func resourceBmInstanceCreate(ctx context.Context, d *schema.ResourceData, m int
304
312
Interfaces : newInterface ,
305
313
}
306
314
315
+ name := d .Get ("name" ).(string )
316
+ if len (name ) > 0 {
317
+ opts .Names = []string {name }
318
+ }
319
+
307
320
nameTpl := d .Get ("name_templates" ).(string )
308
321
if len (nameTpl ) > 0 {
309
322
opts .NameTemplates = []string {nameTpl }
@@ -547,6 +560,18 @@ func resourceBmInstanceUpdate(ctx context.Context, d *schema.ResourceData, m int
547
560
return diag .FromErr (err )
548
561
}
549
562
563
+ if d .HasChange ("name" ) {
564
+ nameTemplate := d .Get ("name_templates" ).(string )
565
+ if len (nameTemplate ) == 0 {
566
+ opts := instances.RenameInstanceOpts {
567
+ Name : d .Get ("name" ).(string ),
568
+ }
569
+ if _ , err := instances .RenameInstance (client , instanceID , opts ).Extract (); err != nil {
570
+ return diag .FromErr (err )
571
+ }
572
+ }
573
+ }
574
+
550
575
if d .HasChange ("metadata" ) {
551
576
omd , nmd := d .GetChange ("metadata" )
552
577
if len (omd .([]interface {})) > 0 {
0 commit comments