github.com/nevins-b/terraform@v0.3.8-0.20170215184714-bbae22007d5a/builtin/providers/ignition/resource_ignition_group.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 resourceGroup() *schema.Resource {
     9  	return &schema.Resource{
    10  		Create: resourceGroupCreate,
    11  		Delete: resourceGroupDelete,
    12  		Exists: resourceGroupExists,
    13  		Read:   resourceGroupRead,
    14  		Schema: map[string]*schema.Schema{
    15  			"name": &schema.Schema{
    16  				Type:     schema.TypeString,
    17  				Required: true,
    18  				ForceNew: true,
    19  			},
    20  			"gid": &schema.Schema{
    21  				Type:     schema.TypeInt,
    22  				Optional: true,
    23  				ForceNew: true,
    24  			},
    25  			"password_hash": &schema.Schema{
    26  				Type:     schema.TypeString,
    27  				Optional: true,
    28  				ForceNew: true,
    29  			},
    30  		},
    31  	}
    32  }
    33  
    34  func resourceGroupCreate(d *schema.ResourceData, meta interface{}) error {
    35  	id, err := buildGroup(d, meta.(*cache))
    36  	if err != nil {
    37  		return err
    38  	}
    39  
    40  	d.SetId(id)
    41  	return nil
    42  }
    43  
    44  func resourceGroupDelete(d *schema.ResourceData, meta interface{}) error {
    45  	d.SetId("")
    46  	return nil
    47  }
    48  
    49  func resourceGroupExists(d *schema.ResourceData, meta interface{}) (bool, error) {
    50  	id, err := buildGroup(d, meta.(*cache))
    51  	if err != nil {
    52  		return false, err
    53  	}
    54  
    55  	return id == d.Id(), nil
    56  }
    57  
    58  func resourceGroupRead(d *schema.ResourceData, meta interface{}) error {
    59  	return nil
    60  }
    61  
    62  func buildGroup(d *schema.ResourceData, c *cache) (string, error) {
    63  	return c.addGroup(&types.Group{
    64  		Name:         d.Get("name").(string),
    65  		PasswordHash: d.Get("password_hash").(string),
    66  		Gid:          getUInt(d, "gid"),
    67  	}), nil
    68  }