2017-01-03 12:29:14 +01:00
|
|
|
package ignition
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/coreos/ignition/config/types"
|
|
|
|
"github.com/hashicorp/terraform/helper/schema"
|
|
|
|
)
|
|
|
|
|
|
|
|
func resourceGroup() *schema.Resource {
|
|
|
|
return &schema.Resource{
|
|
|
|
Exists: resourceGroupExists,
|
|
|
|
Read: resourceGroupRead,
|
|
|
|
Schema: map[string]*schema.Schema{
|
|
|
|
"name": &schema.Schema{
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Required: true,
|
|
|
|
ForceNew: true,
|
|
|
|
},
|
|
|
|
"gid": &schema.Schema{
|
|
|
|
Type: schema.TypeInt,
|
|
|
|
Optional: true,
|
|
|
|
ForceNew: true,
|
|
|
|
},
|
|
|
|
"password_hash": &schema.Schema{
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
ForceNew: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-06 13:23:04 +01:00
|
|
|
func resourceGroupRead(d *schema.ResourceData, meta interface{}) error {
|
2017-01-03 12:29:14 +01:00
|
|
|
id, err := buildGroup(d, meta.(*cache))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
d.SetId(id)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func resourceGroupExists(d *schema.ResourceData, meta interface{}) (bool, error) {
|
|
|
|
id, err := buildGroup(d, meta.(*cache))
|
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return id == d.Id(), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func buildGroup(d *schema.ResourceData, c *cache) (string, error) {
|
|
|
|
return c.addGroup(&types.Group{
|
|
|
|
Name: d.Get("name").(string),
|
|
|
|
PasswordHash: d.Get("password_hash").(string),
|
|
|
|
Gid: getUInt(d, "gid"),
|
|
|
|
}), nil
|
|
|
|
}
|