provider/ignition: Allow to add authorized keys without user creation (#11406)

Fix #11405
This commit is contained in:
Yves Blusseau 2017-01-27 20:24:37 +01:00 committed by Paul Stack
parent 97a2bcecf1
commit 544c21c5f1
2 changed files with 28 additions and 17 deletions

View File

@ -1,6 +1,8 @@
package ignition package ignition
import ( import (
"reflect"
"github.com/coreos/ignition/config/types" "github.com/coreos/ignition/config/types"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
) )
@ -107,11 +109,7 @@ func resourceUserRead(d *schema.ResourceData, meta interface{}) error {
} }
func buildUser(d *schema.ResourceData, c *cache) (string, error) { func buildUser(d *schema.ResourceData, c *cache) (string, error) {
return c.addUser(&types.User{ uc := types.UserCreate{
Name: d.Get("name").(string),
PasswordHash: d.Get("password_hash").(string),
SSHAuthorizedKeys: castSliceInterface(d.Get("ssh_authorized_keys").([]interface{})),
Create: &types.UserCreate{
Uid: getUInt(d, "uid"), Uid: getUInt(d, "uid"),
GECOS: d.Get("gecos").(string), GECOS: d.Get("gecos").(string),
Homedir: d.Get("home_dir").(string), Homedir: d.Get("home_dir").(string),
@ -121,6 +119,19 @@ func buildUser(d *schema.ResourceData, c *cache) (string, error) {
NoUserGroup: d.Get("no_user_group").(bool), NoUserGroup: d.Get("no_user_group").(bool),
NoLogInit: d.Get("no_log_init").(bool), NoLogInit: d.Get("no_log_init").(bool),
Shell: d.Get("shell").(string), Shell: d.Get("shell").(string),
}, }
}), nil
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
} }

View File

@ -95,8 +95,8 @@ func TestIngnitionUser(t *testing.T) {
return fmt.Errorf("name, found %q", u.Name) return fmt.Errorf("name, found %q", u.Name)
} }
if u.Create.Uid != nil { if u.Create != nil {
return fmt.Errorf("uid, found %d", *u.Create.Uid) return fmt.Errorf("create struct found")
} }
return nil return nil