Skip to content

Commit dad0d8e

Browse files
committed
- all resourceFlash-related logic is moved to resource_flash.go
- Remove any duplicate definitions from provider.go
1 parent 0b6e8ee commit dad0d8e

File tree

2 files changed

+14
-44
lines changed

2 files changed

+14
-44
lines changed

provider/provider.go

Lines changed: 12 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,27 @@
11
package provider
22

33
import (
4-
"fmt"
5-
64
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
75
)
86

9-
func resourceFlash() *schema.Resource {
10-
return &schema.Resource{
11-
Create: resourceFlashCreate,
12-
Read: resourceFlashRead,
13-
Delete: resourceFlashDelete,
14-
// No Update function is defined, so ForceNew is required for fields that trigger recreation
7+
func Provider() *schema.Provider {
8+
return &schema.Provider{
159
Schema: map[string]*schema.Schema{
16-
"node": {
17-
Type: schema.TypeInt,
10+
"username": {
11+
Type: schema.TypeString,
1812
Required: true,
19-
Description: "Node ID to flash firmware",
20-
ForceNew: true, // Force resource recreation if this changes
13+
Description: "The username for BMC authentication",
2114
},
22-
"firmware_file": {
15+
"password": {
2316
Type: schema.TypeString,
2417
Required: true,
25-
Description: "Path to the firmware file",
26-
ForceNew: true, // Force resource recreation if this changes
18+
Description: "The password for BMC authentication",
2719
},
2820
},
21+
ResourcesMap: map[string]*schema.Resource{
22+
"turingpi_power": resourcePower(),
23+
"turingpi_flash": resourceFlash(),
24+
"turingpi_node": resourceNode(),
25+
},
2926
}
3027
}
31-
32-
func resourceFlashCreate(d *schema.ResourceData, meta interface{}) error {
33-
node := d.Get("node").(int)
34-
firmware := d.Get("firmware_file").(string)
35-
36-
// Example logic for flashing
37-
fmt.Printf("Flashing node %d with firmware %s\n", node, firmware)
38-
39-
// Set a unique ID for the resource
40-
d.SetId(fmt.Sprintf("node-%d", node))
41-
return nil
42-
}
43-
44-
func resourceFlashRead(d *schema.ResourceData, meta interface{}) error {
45-
// Example logic for reading flash status
46-
fmt.Printf("Reading flash status for node %s\n", d.Id())
47-
return nil
48-
}
49-
50-
func resourceFlashDelete(d *schema.ResourceData, meta interface{}) error {
51-
// Example logic for flash cleanup if needed
52-
fmt.Printf("Deleting flash resource for node %s\n", d.Id())
53-
return nil
54-
}

provider/resource_flash.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ func resourceFlash() *schema.Resource {
1616
Type: schema.TypeInt,
1717
Required: true,
1818
Description: "Node ID to flash firmware",
19+
ForceNew: true,
1920
},
2021
"firmware_file": {
2122
Type: schema.TypeString,
2223
Required: true,
2324
Description: "Path to the firmware file",
25+
ForceNew: true,
2426
},
2527
},
2628
}
@@ -30,22 +32,17 @@ func resourceFlashCreate(d *schema.ResourceData, meta interface{}) error {
3032
node := d.Get("node").(int)
3133
firmware := d.Get("firmware_file").(string)
3234

33-
// Example logic for flashing
3435
fmt.Printf("Flashing node %d with firmware %s\n", node, firmware)
35-
36-
// Set a unique ID for the resource
3736
d.SetId(fmt.Sprintf("node-%d", node))
3837
return nil
3938
}
4039

4140
func resourceFlashRead(d *schema.ResourceData, meta interface{}) error {
42-
// Example logic for reading flash status
4341
fmt.Printf("Reading flash status for node %s\n", d.Id())
4442
return nil
4543
}
4644

4745
func resourceFlashDelete(d *schema.ResourceData, meta interface{}) error {
48-
// Example logic for flash cleanup if needed
4946
fmt.Printf("Deleting flash resource for node %s\n", d.Id())
5047
return nil
5148
}

0 commit comments

Comments
 (0)