Skip to content
This repository was archived by the owner on Mar 1, 2023. It is now read-only.

Commit 37ebeb4

Browse files
committed
GCLOUD2-5422 allow renaming bm instances
1 parent c9cc3f4 commit 37ebeb4

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

docs/resources/gcore_baremetal.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ resource "gcore_baremetal" "bm" {
5050

5151
- **flavor_id** (String)
5252
- **interface** (Block Set, Min: 1) (see [below for nested schema](#nestedblock--interface))
53-
- **name** (String)
5453

5554
### Optional
5655

@@ -62,6 +61,7 @@ resource "gcore_baremetal" "bm" {
6261
- **last_updated** (String)
6362
- **metadata** (Block List, Deprecated) (see [below for nested schema](#nestedblock--metadata))
6463
- **metadata_map** (Map of String)
64+
- **name** (String)
6565
- **name_templates** (String)
6666
- **password** (String)
6767
- **project_id** (Number)

gcore/resource_gcore_baremetal.go

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,20 @@ func resourceBmInstance() *schema.Resource {
8989
},
9090
"name": &schema.Schema{
9191
Type: schema.TypeString,
92-
Required: true,
92+
Optional: true,
93+
Computed: true,
94+
ExactlyOneOf: []string{
95+
"name",
96+
"name_templates",
97+
},
9398
},
9499
"name_templates": &schema.Schema{
95100
Type: schema.TypeString,
96101
Optional: true,
102+
ExactlyOneOf: []string{
103+
"name",
104+
"name_templates",
105+
},
97106
},
98107
"image_id": {
99108
Type: schema.TypeString,
@@ -293,7 +302,6 @@ func resourceBmInstanceCreate(ctx context.Context, d *schema.ResourceData, m int
293302
log.Printf("[DEBUG] Baremetal interfaces: %+v", newInterface)
294303
opts := bminstances.CreateOpts{
295304
Flavor: d.Get("flavor_id").(string),
296-
Names: []string{d.Get("name").(string)},
297305
ImageID: d.Get("image_id").(string),
298306
AppTemplateID: d.Get("apptemplate_id").(string),
299307
Keypair: d.Get("keypair_name").(string),
@@ -304,6 +312,11 @@ func resourceBmInstanceCreate(ctx context.Context, d *schema.ResourceData, m int
304312
Interfaces: newInterface,
305313
}
306314

315+
name := d.Get("name").(string)
316+
if len(name) > 0 {
317+
opts.Names = []string{name}
318+
}
319+
307320
nameTpl := d.Get("name_templates").(string)
308321
if len(nameTpl) > 0 {
309322
opts.NameTemplates = []string{nameTpl}
@@ -547,6 +560,18 @@ func resourceBmInstanceUpdate(ctx context.Context, d *schema.ResourceData, m int
547560
return diag.FromErr(err)
548561
}
549562

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+
550575
if d.HasChange("metadata") {
551576
omd, nmd := d.GetChange("metadata")
552577
if len(omd.([]interface{})) > 0 {

0 commit comments

Comments
 (0)