github.com/vtorhonen/terraform@v0.9.0-beta2.0.20170307220345-5d894e4ffda7/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  		Exists: resourceGroupExists,
    11  		Read:   resourceGroupRead,
    12  		Schema: map[string]*schema.Schema{
    13  			"name": &schema.Schema{
    14  				Type:     schema.TypeString,
    15  				Required: true,
    16  				ForceNew: true,
    17  			},
    18  			"gid": &schema.Schema{
    19  				Type:     schema.TypeInt,
    20  				Optional: true,
    21  				ForceNew: true,
    22  			},
    23  			"password_hash": &schema.Schema{
    24  				Type:     schema.TypeString,
    25  				Optional: true,
    26  				ForceNew: true,
    27  			},
    28  		},
    29  	}
    30  }
    31  
    32  func resourceGroupRead(d *schema.ResourceData, meta interface{}) error {
    33  	id, err := buildGroup(d, meta.(*cache))
    34  	if err != nil {
    35  		return err
    36  	}
    37  
    38  	d.SetId(id)
    39  	return nil
    40  }
    41  
    42  func resourceGroupExists(d *schema.ResourceData, meta interface{}) (bool, error) {
    43  	id, err := buildGroup(d, meta.(*cache))
    44  	if err != nil {
    45  		return false, err
    46  	}
    47  
    48  	return id == d.Id(), nil
    49  }
    50  
    51  func buildGroup(d *schema.ResourceData, c *cache) (string, error) {
    52  	return c.addGroup(&types.Group{
    53  		Name:         d.Get("name").(string),
    54  		PasswordHash: d.Get("password_hash").(string),
    55  		Gid:          getUInt(d, "gid"),
    56  	}), nil
    57  }