github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/ignition/resource_ignition_networkd_unit.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 resourceNetworkdUnit() *schema.Resource { 9 return &schema.Resource{ 10 Exists: resourceNetworkdUnitExists, 11 Read: resourceNetworkdUnitRead, 12 Schema: map[string]*schema.Schema{ 13 "name": &schema.Schema{ 14 Type: schema.TypeString, 15 Required: true, 16 ForceNew: true, 17 }, 18 "content": &schema.Schema{ 19 Type: schema.TypeString, 20 Optional: true, 21 ForceNew: true, 22 }, 23 }, 24 } 25 } 26 27 func resourceNetworkdUnitRead(d *schema.ResourceData, meta interface{}) error { 28 id, err := buildNetworkdUnit(d, globalCache) 29 if err != nil { 30 return err 31 } 32 33 d.SetId(id) 34 return nil 35 } 36 37 func resourceNetworkdUnitDelete(d *schema.ResourceData, meta interface{}) error { 38 d.SetId("") 39 return nil 40 } 41 42 func resourceNetworkdUnitExists(d *schema.ResourceData, meta interface{}) (bool, error) { 43 id, err := buildNetworkdUnit(d, globalCache) 44 if err != nil { 45 return false, err 46 } 47 48 return id == d.Id(), nil 49 } 50 51 func buildNetworkdUnit(d *schema.ResourceData, c *cache) (string, error) { 52 if err := validateUnitContent(d.Get("content").(string)); err != nil { 53 return "", err 54 } 55 56 return c.addNetworkdUnit(&types.NetworkdUnit{ 57 Name: types.NetworkdUnitName(d.Get("name").(string)), 58 Contents: d.Get("content").(string), 59 }), nil 60 }