2017-01-03 12:29:14 +01:00
|
|
|
package ignition
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/coreos/ignition/config/types"
|
|
|
|
"github.com/hashicorp/terraform/helper/schema"
|
|
|
|
)
|
|
|
|
|
|
|
|
func resourceNetworkdUnit() *schema.Resource {
|
|
|
|
return &schema.Resource{
|
|
|
|
Exists: resourceNetworkdUnitExists,
|
|
|
|
Read: resourceNetworkdUnitRead,
|
|
|
|
Schema: map[string]*schema.Schema{
|
|
|
|
"name": &schema.Schema{
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Required: true,
|
|
|
|
ForceNew: true,
|
|
|
|
},
|
|
|
|
"content": &schema.Schema{
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
ForceNew: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-06 13:23:04 +01:00
|
|
|
func resourceNetworkdUnitRead(d *schema.ResourceData, meta interface{}) error {
|
2017-01-03 12:29:14 +01:00
|
|
|
id, err := buildNetworkdUnit(d, meta.(*cache))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
d.SetId(id)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func resourceNetworkdUnitDelete(d *schema.ResourceData, meta interface{}) error {
|
|
|
|
d.SetId("")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func resourceNetworkdUnitExists(d *schema.ResourceData, meta interface{}) (bool, error) {
|
|
|
|
id, err := buildNetworkdUnit(d, meta.(*cache))
|
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return id == d.Id(), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func buildNetworkdUnit(d *schema.ResourceData, c *cache) (string, error) {
|
2017-01-17 12:49:45 +01:00
|
|
|
if err := validateUnitContent(d.Get("content").(string)); err != nil {
|
2017-01-03 12:29:14 +01:00
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
return c.addNetworkdUnit(&types.NetworkdUnit{
|
|
|
|
Name: types.NetworkdUnitName(d.Get("name").(string)),
|
|
|
|
Contents: d.Get("content").(string),
|
|
|
|
}), nil
|
|
|
|
}
|