forked from hashicorp/terraform
-
Notifications
You must be signed in to change notification settings - Fork 2
/
resource_ignition_raid.go
69 lines (61 loc) · 1.48 KB
/
resource_ignition_raid.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package ignition
import (
"github.com/coreos/ignition/config/types"
"github.com/hashicorp/terraform/helper/schema"
)
func resourceRaid() *schema.Resource {
return &schema.Resource{
Exists: resourceRaidExists,
Read: resourceRaidRead,
Schema: map[string]*schema.Schema{
"name": &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"level": &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"devices": &schema.Schema{
Type: schema.TypeList,
Optional: true,
ForceNew: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"spares": &schema.Schema{
Type: schema.TypeInt,
Optional: true,
ForceNew: true,
},
},
}
}
func resourceRaidRead(d *schema.ResourceData, meta interface{}) error {
id, err := buildRaid(d, meta.(*cache))
if err != nil {
return err
}
d.SetId(id)
return nil
}
func resourceRaidExists(d *schema.ResourceData, meta interface{}) (bool, error) {
id, err := buildRaid(d, meta.(*cache))
if err != nil {
return false, err
}
return id == d.Id(), nil
}
func buildRaid(d *schema.ResourceData, c *cache) (string, error) {
var devices []types.Path
for _, value := range d.Get("devices").([]interface{}) {
devices = append(devices, types.Path(value.(string)))
}
return c.addRaid(&types.Raid{
Name: d.Get("name").(string),
Level: d.Get("level").(string),
Devices: devices,
Spares: d.Get("spares").(int),
}), nil
}