github.com/recobe182/terraform@v0.8.5-0.20170117231232-49ab22a935b7/builtin/providers/ignition/resource_ignition_raid.go (about) 1 package ignition 2 3 import ( 4 "github.com/coreos/ignition/config/types" 5 "github.com/hashicorp/terraform/helper/schema" 6 ) 7 8 func resourceRaid() *schema.Resource { 9 return &schema.Resource{ 10 Create: resourceRaidCreate, 11 Delete: resourceRaidDelete, 12 Exists: resourceRaidExists, 13 Read: resourceRaidRead, 14 Schema: map[string]*schema.Schema{ 15 "name": &schema.Schema{ 16 Type: schema.TypeString, 17 Required: true, 18 ForceNew: true, 19 }, 20 "level": &schema.Schema{ 21 Type: schema.TypeString, 22 Required: true, 23 ForceNew: true, 24 }, 25 "devices": &schema.Schema{ 26 Type: schema.TypeList, 27 Optional: true, 28 ForceNew: true, 29 Elem: &schema.Schema{Type: schema.TypeString}, 30 }, 31 "spares": &schema.Schema{ 32 Type: schema.TypeInt, 33 Optional: true, 34 ForceNew: true, 35 }, 36 }, 37 } 38 } 39 40 func resourceRaidCreate(d *schema.ResourceData, meta interface{}) error { 41 id, err := buildRaid(d, meta.(*cache)) 42 if err != nil { 43 return err 44 } 45 46 d.SetId(id) 47 return nil 48 } 49 50 func resourceRaidDelete(d *schema.ResourceData, meta interface{}) error { 51 d.SetId("") 52 return nil 53 } 54 55 func resourceRaidExists(d *schema.ResourceData, meta interface{}) (bool, error) { 56 id, err := buildRaid(d, meta.(*cache)) 57 if err != nil { 58 return false, err 59 } 60 61 return id == d.Id(), nil 62 } 63 64 func resourceRaidRead(d *schema.ResourceData, meta interface{}) error { 65 return nil 66 } 67 68 func buildRaid(d *schema.ResourceData, c *cache) (string, error) { 69 var devices []types.Path 70 for _, value := range d.Get("devices").([]interface{}) { 71 devices = append(devices, types.Path(value.(string))) 72 } 73 74 return c.addRaid(&types.Raid{ 75 Name: d.Get("name").(string), 76 Level: d.Get("level").(string), 77 Devices: devices, 78 Spares: d.Get("spares").(int), 79 }), nil 80 }