github.com/recobe182/terraform@v0.8.5-0.20170117231232-49ab22a935b7/builtin/providers/ignition/resource_ignition_user.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 resourceUser() *schema.Resource { 9 return &schema.Resource{ 10 Create: resourceUserCreate, 11 Delete: resourceUserDelete, 12 Exists: resourceUserExists, 13 Read: resourceUserRead, 14 Schema: map[string]*schema.Schema{ 15 "name": &schema.Schema{ 16 Type: schema.TypeString, 17 Required: true, 18 ForceNew: true, 19 }, 20 "password_hash": &schema.Schema{ 21 Type: schema.TypeString, 22 Optional: true, 23 ForceNew: true, 24 }, 25 "ssh_authorized_keys": &schema.Schema{ 26 Type: schema.TypeList, 27 Optional: true, 28 ForceNew: true, 29 Elem: &schema.Schema{Type: schema.TypeString}, 30 }, 31 "uid": &schema.Schema{ 32 Type: schema.TypeInt, 33 Optional: true, 34 ForceNew: true, 35 }, 36 "gecos": &schema.Schema{ 37 Type: schema.TypeString, 38 Optional: true, 39 ForceNew: true, 40 }, 41 "home_dir": &schema.Schema{ 42 Type: schema.TypeString, 43 Optional: true, 44 ForceNew: true, 45 }, 46 "no_create_home": &schema.Schema{ 47 Type: schema.TypeBool, 48 Optional: true, 49 ForceNew: true, 50 }, 51 "primary_group": &schema.Schema{ 52 Type: schema.TypeString, 53 Optional: true, 54 ForceNew: true, 55 }, 56 "groups": &schema.Schema{ 57 Type: schema.TypeList, 58 Optional: true, 59 ForceNew: true, 60 Elem: &schema.Schema{Type: schema.TypeString}, 61 }, 62 "no_user_group": &schema.Schema{ 63 Type: schema.TypeBool, 64 Optional: true, 65 ForceNew: true, 66 }, 67 "no_log_init": &schema.Schema{ 68 Type: schema.TypeBool, 69 Optional: true, 70 ForceNew: true, 71 }, 72 "shell": &schema.Schema{ 73 Type: schema.TypeString, 74 Optional: true, 75 ForceNew: true, 76 }, 77 }, 78 } 79 } 80 81 func resourceUserCreate(d *schema.ResourceData, meta interface{}) error { 82 id, err := buildUser(d, meta.(*cache)) 83 if err != nil { 84 return err 85 } 86 87 d.SetId(id) 88 return nil 89 } 90 91 func resourceUserDelete(d *schema.ResourceData, meta interface{}) error { 92 d.SetId("") 93 return nil 94 } 95 96 func resourceUserExists(d *schema.ResourceData, meta interface{}) (bool, error) { 97 id, err := buildUser(d, meta.(*cache)) 98 if err != nil { 99 return false, err 100 } 101 102 return id == d.Id(), nil 103 } 104 105 func resourceUserRead(d *schema.ResourceData, meta interface{}) error { 106 return nil 107 } 108 109 func buildUser(d *schema.ResourceData, c *cache) (string, error) { 110 return c.addUser(&types.User{ 111 Name: d.Get("name").(string), 112 PasswordHash: d.Get("password_hash").(string), 113 SSHAuthorizedKeys: castSliceInterface(d.Get("ssh_authorized_keys").([]interface{})), 114 Create: &types.UserCreate{ 115 Uid: getUInt(d, "uid"), 116 GECOS: d.Get("gecos").(string), 117 Homedir: d.Get("home_dir").(string), 118 NoCreateHome: d.Get("no_create_home").(bool), 119 PrimaryGroup: d.Get("primary_group").(string), 120 Groups: castSliceInterface(d.Get("groups").([]interface{})), 121 NoUserGroup: d.Get("no_user_group").(bool), 122 NoLogInit: d.Get("no_log_init").(bool), 123 Shell: d.Get("shell").(string), 124 }, 125 }), nil 126 }