github.com/recobe182/terraform@v0.8.5-0.20170117231232-49ab22a935b7/builtin/providers/ignition/resource_ignition_disk.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 resourceDisk() *schema.Resource { 9 return &schema.Resource{ 10 Create: resourceDiskCreate, 11 Delete: resourceDiskDelete, 12 Exists: resourceDiskExists, 13 Read: resourceDiskRead, 14 Schema: map[string]*schema.Schema{ 15 "device": &schema.Schema{ 16 Type: schema.TypeString, 17 Required: true, 18 ForceNew: true, 19 }, 20 "wipe_table": &schema.Schema{ 21 Type: schema.TypeBool, 22 Optional: true, 23 ForceNew: true, 24 }, 25 "partition": &schema.Schema{ 26 Type: schema.TypeList, 27 Optional: true, 28 ForceNew: true, 29 Elem: &schema.Resource{ 30 Schema: map[string]*schema.Schema{ 31 "label": &schema.Schema{ 32 Type: schema.TypeString, 33 Optional: true, 34 ForceNew: true, 35 }, 36 "number": &schema.Schema{ 37 Type: schema.TypeInt, 38 Optional: true, 39 ForceNew: true, 40 }, 41 "size": &schema.Schema{ 42 Type: schema.TypeInt, 43 Optional: true, 44 ForceNew: true, 45 }, 46 "start": &schema.Schema{ 47 Type: schema.TypeInt, 48 Optional: true, 49 ForceNew: true, 50 }, 51 "type_guid": &schema.Schema{ 52 Type: schema.TypeString, 53 Optional: true, 54 ForceNew: true, 55 }, 56 }, 57 }, 58 }, 59 }, 60 } 61 } 62 63 func resourceDiskCreate(d *schema.ResourceData, meta interface{}) error { 64 id, err := buildDisk(d, meta.(*cache)) 65 if err != nil { 66 return err 67 } 68 69 d.SetId(id) 70 return nil 71 } 72 73 func resourceDiskDelete(d *schema.ResourceData, meta interface{}) error { 74 d.SetId("") 75 return nil 76 } 77 78 func resourceDiskExists(d *schema.ResourceData, meta interface{}) (bool, error) { 79 id, err := buildDisk(d, meta.(*cache)) 80 if err != nil { 81 return false, err 82 } 83 84 return id == d.Id(), nil 85 } 86 87 func resourceDiskRead(d *schema.ResourceData, meta interface{}) error { 88 return nil 89 } 90 91 func buildDisk(d *schema.ResourceData, c *cache) (string, error) { 92 var partitions []types.Partition 93 for _, raw := range d.Get("partition").([]interface{}) { 94 v := raw.(map[string]interface{}) 95 96 partitions = append(partitions, types.Partition{ 97 Label: types.PartitionLabel(v["label"].(string)), 98 Number: v["number"].(int), 99 Size: types.PartitionDimension(v["size"].(int)), 100 Start: types.PartitionDimension(v["start"].(int)), 101 TypeGUID: types.PartitionTypeGUID(v["type_guid"].(string)), 102 }) 103 } 104 105 return c.addDisk(&types.Disk{ 106 Device: types.Path(d.Get("device").(string)), 107 WipeTable: d.Get("wipe_table").(bool), 108 Partitions: partitions, 109 }), nil 110 }