Skip to content

Commit 9ddb9fc

Browse files
fix: allow definition of multivalued user profile attributes (#1071)
In order to replicate the existing userprofile configuration, we need to support the multivalued attribute. We now support the `multi_valued = bool` attribute. Example: ```hcl attribute { name = "myAttr" multi_valued = true validator { name = "options" config = { options = jsonencode(["opt1", "opt2", "opt3"]) } } annotations = { foo = jsonencode({ "key" : "val" }) } } ``` Fixes #1064 Signed-off-by: Thomas Darimont <[email protected]>
1 parent 82b520f commit 9ddb9fc

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
lines changed

docs/resources/realm_user_profile.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ resource "keycloak_realm_user_profile" "userprofile" {
2828
display_name = "Field 1"
2929
group = "group1"
3030
31+
multi_valued = false
3132
enabled_when_scope = ["offline_access"]
3233
3334
required_for_roles = ["user"]
@@ -98,6 +99,7 @@ resource "keycloak_realm_user_profile" "userprofile" {
9899

99100
- `name` - (Required) The name of the attribute.
100101
- `display_name` - (Optional) The display name of the attribute.
102+
- `multi_valued` - (Optional) If the attribute supports multiple values. Defaults to `false`.
101103
- `group` - (Optional) The group that the attribute belong to.
102104
- `enabled_when_scope` - (Optional) A list of scopes. The attribute will only be enabled when these scopes are requested by clients.
103105
- `required_for_roles` - (Optional) A list of roles for which the attribute will be required.

keycloak/realm_user_profile.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type RealmUserProfileAttribute struct {
2727
DisplayName string `json:"displayName,omitempty"`
2828
Group string `json:"group,omitempty"`
2929
Name string `json:"name"`
30+
MultiValued bool `json:"multivalued,omitempty"`
3031
Permissions *RealmUserProfilePermissions `json:"permissions,omitempty"`
3132
Required *RealmUserProfileRequired `json:"required,omitempty"`
3233
Selector *RealmUserProfileSelector `json:"selector,omitempty"`

provider/resource_keycloak_realm_user_profile.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ func resourceKeycloakRealmUserProfile() *schema.Resource {
4646
Type: schema.TypeString,
4747
Optional: true,
4848
},
49+
"multi_valued": {
50+
Type: schema.TypeBool,
51+
Optional: true,
52+
Default: false,
53+
},
4954
"group": {
5055
Type: schema.TypeString,
5156
Optional: true,
@@ -153,6 +158,12 @@ func getRealmUserProfileAttributeFromData(m map[string]interface{}) *keycloak.Re
153158
Group: m["group"].(string),
154159
}
155160

161+
if v, ok := m["multivalued"].(bool); ok {
162+
attribute.MultiValued = v
163+
} else {
164+
attribute.MultiValued = false
165+
}
166+
156167
if v, ok := m["permissions"]; ok && len(v.([]interface{})) > 0 {
157168
permissions := keycloak.RealmUserProfilePermissions{
158169
Edit: make([]string, 0),
@@ -329,6 +340,8 @@ func getRealmUserProfileAttributeData(attr *keycloak.RealmUserProfileAttribute)
329340
attributeData["name"] = attr.Name
330341

331342
attributeData["display_name"] = attr.DisplayName
343+
attributeData["multi_valued"] = attr.MultiValued
344+
332345
attributeData["group"] = attr.Group
333346
if attr.Selector != nil && len(attr.Selector.Scopes) != 0 {
334347
attributeData["enabled_when_scope"] = attr.Selector.Scopes

provider/resource_keycloak_realm_user_profile_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ func TestAccKeycloakRealmUserProfile_basicFull(t *testing.T) {
106106
{
107107
Name: "attribute2",
108108
DisplayName: "attribute 2",
109+
MultiValued: false,
109110
Group: "group",
110111
Selector: &keycloak.RealmUserProfileSelector{Scopes: []string{"roles"}},
111112
Required: &keycloak.RealmUserProfileRequired{

0 commit comments

Comments
 (0)