diff options
author | Flavio Castelli <fcastelli@suse.com> | 2017-05-03 11:37:08 +0200 |
---|---|---|
committer | Alvaro <alvaro.saurin@gmail.com> | 2017-05-03 11:40:31 +0200 |
commit | ee12004ab93e54f326896e9909ba9e6a2bd11e89 (patch) | |
tree | 1ea30d204b04425ebd1dadaf8cc991d572c7f0fb /vendor/github.com/hashicorp/terraform/builtin/providers/ignition/resource_ignition_user.go | |
parent | a286dc5494691c2b04c48ef6695ed0c902912c0f (diff) | |
download | terraform-provider-libvirt-ee12004ab93e54f326896e9909ba9e6a2bd11e89.tar terraform-provider-libvirt-ee12004ab93e54f326896e9909ba9e6a2bd11e89.tar.gz |
Vendor dependencies with vndr
This fixes issue #123
Diffstat (limited to 'vendor/github.com/hashicorp/terraform/builtin/providers/ignition/resource_ignition_user.go')
-rw-r--r-- | vendor/github.com/hashicorp/terraform/builtin/providers/ignition/resource_ignition_user.go | 126 |
1 files changed, 126 insertions, 0 deletions
diff --git a/vendor/github.com/hashicorp/terraform/builtin/providers/ignition/resource_ignition_user.go b/vendor/github.com/hashicorp/terraform/builtin/providers/ignition/resource_ignition_user.go new file mode 100644 index 00000000..183e6c8c --- /dev/null +++ b/vendor/github.com/hashicorp/terraform/builtin/providers/ignition/resource_ignition_user.go @@ -0,0 +1,126 @@ +package ignition + +import ( + "reflect" + + "github.com/coreos/ignition/config/types" + "github.com/hashicorp/terraform/helper/schema" +) + +func resourceUser() *schema.Resource { + return &schema.Resource{ + Exists: resourceUserExists, + Read: resourceUserRead, + Schema: map[string]*schema.Schema{ + "name": &schema.Schema{ + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "password_hash": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + "ssh_authorized_keys": &schema.Schema{ + Type: schema.TypeList, + Optional: true, + ForceNew: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "uid": &schema.Schema{ + Type: schema.TypeInt, + Optional: true, + ForceNew: true, + }, + "gecos": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + "home_dir": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + "no_create_home": &schema.Schema{ + Type: schema.TypeBool, + Optional: true, + ForceNew: true, + }, + "primary_group": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + "groups": &schema.Schema{ + Type: schema.TypeList, + Optional: true, + ForceNew: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "no_user_group": &schema.Schema{ + Type: schema.TypeBool, + Optional: true, + ForceNew: true, + }, + "no_log_init": &schema.Schema{ + Type: schema.TypeBool, + Optional: true, + ForceNew: true, + }, + "shell": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + }, + } +} + +func resourceUserRead(d *schema.ResourceData, meta interface{}) error { + id, err := buildUser(d, globalCache) + if err != nil { + return err + } + + d.SetId(id) + return nil +} + +func resourceUserExists(d *schema.ResourceData, meta interface{}) (bool, error) { + id, err := buildUser(d, globalCache) + if err != nil { + return false, err + } + + return id == d.Id(), nil +} + +func buildUser(d *schema.ResourceData, c *cache) (string, error) { + uc := types.UserCreate{ + Uid: getUInt(d, "uid"), + GECOS: d.Get("gecos").(string), + Homedir: d.Get("home_dir").(string), + NoCreateHome: d.Get("no_create_home").(bool), + PrimaryGroup: d.Get("primary_group").(string), + Groups: castSliceInterface(d.Get("groups").([]interface{})), + NoUserGroup: d.Get("no_user_group").(bool), + NoLogInit: d.Get("no_log_init").(bool), + Shell: d.Get("shell").(string), + } + + puc := &uc + if reflect.DeepEqual(uc, types.UserCreate{}) { // check if the struct is empty + puc = nil + } + + user := types.User{ + Name: d.Get("name").(string), + PasswordHash: d.Get("password_hash").(string), + SSHAuthorizedKeys: castSliceInterface(d.Get("ssh_authorized_keys").([]interface{})), + Create: puc, + } + + return c.addUser(&user), nil +} |