diff --git a/internal/resource/user.go b/internal/resource/user.go index a7b5c19..67ce7ed 100644 --- a/internal/resource/user.go +++ b/internal/resource/user.go @@ -182,6 +182,11 @@ func (u *User) UseConfig(config data.ConfigurationValueGetter) { } func (u *User) ResolveId(ctx context.Context) string { + if u.config != nil { + if configUser, configUserErr := u.config.GetValue("user"); configUserErr == nil && u.Name == "" { + u.Name = configUser.(string) + } + } return LookupUIDString(u.Name) } diff --git a/internal/resource/user_test.go b/internal/resource/user_test.go index 803d746..39930d9 100644 --- a/internal/resource/user_test.go +++ b/internal/resource/user_test.go @@ -13,6 +13,7 @@ import ( _ "os" _ "strings" "testing" + "decl/internal/data" ) func TestNewUserResource(t *testing.T) { @@ -77,3 +78,22 @@ func TestCreateUser(t *testing.T) { applyDeleteErr := u.Apply() assert.Equal(t, nil, applyDeleteErr) } + +func TestSystemUser(t *testing.T) { + u := NewUser() + + u.UseConfig(MockConfigValueGetter(func(key string) (any, error) { + switch key { + case "user": + return "bar", nil + case "group": + return "foo", nil + case "uid": + return "", nil + } + return nil, fmt.Errorf("%w: %s", data.ErrUnknownConfigurationKey, key) + })) + + u.ResolveId(context.Background()) + assert.Equal(t, "bar", u.Name) +}