Skip to content
New issue

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

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

Already on GitHub? # to your account

fix: don't set "defaultRole" within realm JSON when sending requests to Keycloak #612

Merged
merged 2 commits into from
Oct 14, 2021
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
4 changes: 2 additions & 2 deletions docs/resources/default_roles.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ page_title: "keycloak_default_roles Resource"

# keycloak\_default\_roles Resource

Allows managing default roles within Keycloak.
Allows managing default realm roles within Keycloak.

Roles allow you define privileges within Keycloak and map them to users and groups.
Note: This feature was added in Keycloak v13, so this resource will not work on older versions of Keycloak.

## Example Usage (Realm role)

Expand Down
2 changes: 1 addition & 1 deletion keycloak/realm.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ type Realm struct {
WebAuthnPolicyPasswordlessUserVerificationRequirement string `json:"webAuthnPolicyPasswordlessUserVerificationRequirement"`

// Roles
DefaultRole Role `json:"defaultRole"`
DefaultRole *Role `json:"defaultRole,omitempty"`
}

type BrowserSecurityHeaders struct {
Expand Down
7 changes: 7 additions & 0 deletions provider/resource_keycloak_default_roles.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package provider

import (
"errors"
"fmt"
"strings"

Expand Down Expand Up @@ -84,6 +85,12 @@ func resourceKeycloakDefaultRolesRead(data *schema.ResourceData, meta interface{
func resourceKeycloakDefaultRolesReconcile(data *schema.ResourceData, meta interface{}) error {
keycloakClient := meta.(*keycloak.KeycloakClient)

if ok, err := keycloakClient.VersionIsGreaterThanOrEqualTo(keycloak.Version_13); !ok && err != nil {
return errors.New("this resource requires Keycloak v13 or higher")
} else if err != nil {
return err
}

defaultRoles := mapFromDataToDefaultRoles(data)

realm, err := keycloakClient.GetRealm(defaultRoles.RealmId)
Expand Down