github.com/recobe182/terraform@v0.8.5-0.20170117231232-49ab22a935b7/builtin/providers/ignition/resource_ignition_filesystem.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 resourceFilesystem() *schema.Resource { 9 return &schema.Resource{ 10 Create: resourceFilesystemCreate, 11 Delete: resourceFilesystemDelete, 12 Exists: resourceFilesystemExists, 13 Read: resourceFilesystemRead, 14 Schema: map[string]*schema.Schema{ 15 "name": &schema.Schema{ 16 Type: schema.TypeString, 17 Optional: true, 18 ForceNew: true, 19 }, 20 "mount": &schema.Schema{ 21 Type: schema.TypeList, 22 Optional: true, 23 ForceNew: true, 24 MaxItems: 1, 25 Elem: &schema.Resource{ 26 Schema: map[string]*schema.Schema{ 27 "device": &schema.Schema{ 28 Type: schema.TypeString, 29 Required: true, 30 ForceNew: true, 31 }, 32 "format": &schema.Schema{ 33 Type: schema.TypeString, 34 Required: true, 35 ForceNew: true, 36 }, 37 "force": &schema.Schema{ 38 Type: schema.TypeBool, 39 Optional: true, 40 ForceNew: true, 41 }, 42 "options": &schema.Schema{ 43 Type: schema.TypeList, 44 Optional: true, 45 ForceNew: true, 46 Elem: &schema.Schema{Type: schema.TypeString}, 47 }, 48 }, 49 }, 50 }, 51 "path": &schema.Schema{ 52 Type: schema.TypeString, 53 Optional: true, 54 ForceNew: true, 55 }, 56 }, 57 } 58 } 59 60 func resourceFilesystemCreate(d *schema.ResourceData, meta interface{}) error { 61 id, err := buildFilesystem(d, meta.(*cache)) 62 if err != nil { 63 return err 64 } 65 66 d.SetId(id) 67 return nil 68 } 69 70 func resourceFilesystemDelete(d *schema.ResourceData, meta interface{}) error { 71 d.SetId("") 72 return nil 73 } 74 75 func resourceFilesystemExists(d *schema.ResourceData, meta interface{}) (bool, error) { 76 id, err := buildFilesystem(d, meta.(*cache)) 77 if err != nil { 78 return false, err 79 } 80 81 return id == d.Id(), nil 82 } 83 84 func resourceFilesystemRead(d *schema.ResourceData, meta interface{}) error { 85 return nil 86 } 87 88 func buildFilesystem(d *schema.ResourceData, c *cache) (string, error) { 89 var mount *types.FilesystemMount 90 if _, ok := d.GetOk("mount"); ok { 91 mount = &types.FilesystemMount{ 92 Device: types.Path(d.Get("mount.0.device").(string)), 93 Format: types.FilesystemFormat(d.Get("mount.0.format").(string)), 94 } 95 96 force, hasForce := d.GetOk("mount.0.force") 97 options, hasOptions := d.GetOk("mount.0.options") 98 if hasOptions || hasForce { 99 mount.Create = &types.FilesystemCreate{ 100 Force: force.(bool), 101 Options: castSliceInterface(options.([]interface{})), 102 } 103 } 104 } 105 106 path := types.Path(d.Get("path").(string)) 107 108 return c.addFilesystem(&types.Filesystem{ 109 Name: d.Get("name").(string), 110 Mount: mount, 111 Path: &path, 112 }), nil 113 }