Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow definition of multivalued user profile attributes #1071

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/resources/realm_user_profile.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ resource "keycloak_realm_user_profile" "userprofile" {
display_name = "Field 1"
group = "group1"
multi_valued = false
enabled_when_scope = ["offline_access"]
required_for_roles = ["user"]
Expand Down Expand Up @@ -98,6 +99,7 @@ resource "keycloak_realm_user_profile" "userprofile" {

- `name` - (Required) The name of the attribute.
- `display_name` - (Optional) The display name of the attribute.
- `multi_valued` - (Optional) If the attribute supports multiple values. Defaults to `false`.
- `group` - (Optional) The group that the attribute belong to.
- `enabled_when_scope` - (Optional) A list of scopes. The attribute will only be enabled when these scopes are requested by clients.
- `required_for_roles` - (Optional) A list of roles for which the attribute will be required.
Expand Down
1 change: 1 addition & 0 deletions keycloak/realm_user_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type RealmUserProfileAttribute struct {
DisplayName string `json:"displayName,omitempty"`
Group string `json:"group,omitempty"`
Name string `json:"name"`
MultiValued bool `json:"multivalued,omitempty"`
Permissions *RealmUserProfilePermissions `json:"permissions,omitempty"`
Required *RealmUserProfileRequired `json:"required,omitempty"`
Selector *RealmUserProfileSelector `json:"selector,omitempty"`
Expand Down
13 changes: 13 additions & 0 deletions provider/resource_keycloak_realm_user_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ func resourceKeycloakRealmUserProfile() *schema.Resource {
Type: schema.TypeString,
Optional: true,
},
"multi_valued": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"group": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -153,6 +158,12 @@ func getRealmUserProfileAttributeFromData(m map[string]interface{}) *keycloak.Re
Group: m["group"].(string),
}

if v, ok := m["multivalued"].(bool); ok {
attribute.MultiValued = v
} else {
attribute.MultiValued = false
}

if v, ok := m["permissions"]; ok && len(v.([]interface{})) > 0 {
permissions := keycloak.RealmUserProfilePermissions{
Edit: make([]string, 0),
Expand Down Expand Up @@ -329,6 +340,8 @@ func getRealmUserProfileAttributeData(attr *keycloak.RealmUserProfileAttribute)
attributeData["name"] = attr.Name

attributeData["display_name"] = attr.DisplayName
attributeData["multi_valued"] = attr.MultiValued

attributeData["group"] = attr.Group
if attr.Selector != nil && len(attr.Selector.Scopes) != 0 {
attributeData["enabled_when_scope"] = attr.Selector.Scopes
Expand Down
1 change: 1 addition & 0 deletions provider/resource_keycloak_realm_user_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ func TestAccKeycloakRealmUserProfile_basicFull(t *testing.T) {
{
Name: "attribute2",
DisplayName: "attribute 2",
MultiValued: false,
Group: "group",
Selector: &keycloak.RealmUserProfileSelector{Scopes: []string{"roles"}},
Required: &keycloak.RealmUserProfileRequired{
Expand Down