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

Feature/update to v5.1.1 #1108

Closed
wants to merge 4 commits into from
Closed
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
8 changes: 6 additions & 2 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@ name: "CodeQL"

on:
push:
branches: [ main ]
branches:
- "main"
- "release/*"
paths-ignore:
- '**/*.md'
pull_request:
# The branches below must be a subset of the branches above
branches: [ main ]
branches:
- "main"
- "release/*"
paths-ignore:
- '**/*.md'
schedule:
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ name: test
on:
push:
branches:
- main
- "main"
- "release/*"
paths-ignore:
- '**/*.md'
pull_request:
branches:
- main
- "main"
- "release/*"
paths-ignore:
- '**/*.md'

Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
## 5.1.1 (January 31, 2025)

IMPROVEMENTS:

* 1100 run ci on release branches ([#1102](https://github.com/keycloak/terraform-provider-keycloak/pull/1102))

BUG FIXES:

* 1091 fixed provider crash with initial_login set to false ([#1103](https://github.com/keycloak/terraform-provider-keycloak/pull/1103))
* 1099 fix multi-valued user attributes cannot be enabled by ([#1107](https://github.com/keycloak/terraform-provider-keycloak/pull/1107))

## 5.1.0 (January 24, 2025)

Expand Down
50 changes: 16 additions & 34 deletions keycloak/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,54 +39,36 @@ func (v Version) AsVersion() *version.Version {
return vv
}

func (KeycloakClient *KeycloakClient) Version() *version.Version {
return KeycloakClient.version
}

func (keycloakClient *KeycloakClient) VersionIsGreaterThanOrEqualTo(ctx context.Context, versionString Version) (bool, error) {
if keycloakClient.version == nil {
err := keycloakClient.login(ctx)
func (KeycloakClient *KeycloakClient) Version(ctx context.Context) (*version.Version, error) {
if KeycloakClient.version == nil {
err := KeycloakClient.login(ctx)
if err != nil {
return false, err
return nil, err
}
}
return KeycloakClient.version, nil
}

v, err := version.NewVersion(string(versionString))
func (keycloakClient *KeycloakClient) VersionIsGreaterThanOrEqualTo(ctx context.Context, versionString Version) (bool, error) {
version, err := keycloakClient.Version(ctx)
if err != nil {
return false, nil
return false, err
}

return keycloakClient.version.GreaterThanOrEqual(v), nil
return version.GreaterThanOrEqual(versionString.AsVersion()), nil
}

func (keycloakClient *KeycloakClient) VersionIsLessThanOrEqualTo(ctx context.Context, versionString Version) (bool, error) {
if keycloakClient.version == nil {
err := keycloakClient.login(ctx)
if err != nil {
return false, err
}
}

v, err := version.NewVersion(string(versionString))
version, err := keycloakClient.Version(ctx)
if err != nil {
return false, nil
return false, err
}

return keycloakClient.version.LessThanOrEqual(v), nil
return version.LessThanOrEqual(versionString.AsVersion()), nil
}

func (keycloakClient *KeycloakClient) VersionIsLessThan(ctx context.Context, versionString Version) (bool, error) {
if keycloakClient.version == nil {
err := keycloakClient.login(ctx)
if err != nil {
return false, err
}
}

v, err := version.NewVersion(string(versionString))
version, err := keycloakClient.Version(ctx)
if err != nil {
return false, nil
return false, err
}

return keycloakClient.version.LessThan(v), nil
return version.LessThan(versionString.AsVersion()), nil
}
5 changes: 4 additions & 1 deletion provider/data_source_keycloak_realm.go
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,10 @@ func dataSourceKeycloakRealm() *schema.Resource {

func dataSourceKeycloakRealmRead(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics {
keycloakClient := meta.(*keycloak.KeycloakClient)
keycloakVersion := keycloakClient.Version()
keycloakVersion, err := keycloakClient.Version(ctx)
if err != nil {
return diag.FromErr(err)
}

realmName := data.Get("realm").(string)

Expand Down
16 changes: 13 additions & 3 deletions provider/generic_keycloak_identity_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,11 @@ func resourceKeycloakIdentityProviderImport(_ context.Context, d *schema.Resourc
func resourceKeycloakIdentityProviderCreate(getIdentityProviderFromData identityProviderDataGetterFunc, setDataFromIdentityProvider identityProviderDataSetterFunc) func(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics {
return func(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics {
keycloakClient := meta.(*keycloak.KeycloakClient)
keycloakVersion := keycloakClient.Version()
keycloakVersion, err := keycloakClient.Version(ctx)
if err != nil {
return diag.FromErr(err)
}

identityProvider, err := getIdentityProviderFromData(data, keycloakVersion)
if err != nil {
return diag.FromErr(err)
Expand All @@ -224,7 +228,10 @@ func resourceKeycloakIdentityProviderCreate(getIdentityProviderFromData identity
func resourceKeycloakIdentityProviderRead(setDataFromIdentityProvider identityProviderDataSetterFunc) func(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics {
return func(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics {
keycloakClient := meta.(*keycloak.KeycloakClient)
keycloakVersion := keycloakClient.Version()
keycloakVersion, err := keycloakClient.Version(ctx)
if err != nil {
return diag.FromErr(err)
}
realm := data.Get("realm").(string)
alias := data.Get("alias").(string)
identityProvider, err := keycloakClient.GetIdentityProvider(ctx, realm, alias)
Expand All @@ -239,7 +246,10 @@ func resourceKeycloakIdentityProviderRead(setDataFromIdentityProvider identityPr
func resourceKeycloakIdentityProviderUpdate(getIdentityProviderFromData identityProviderDataGetterFunc, setDataFromIdentityProvider identityProviderDataSetterFunc) func(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics {
return func(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics {
keycloakClient := meta.(*keycloak.KeycloakClient)
keycloakVersion := keycloakClient.Version()
keycloakVersion, err := keycloakClient.Version(ctx)
if err != nil {
return diag.FromErr(err)
}
identityProvider, err := getIdentityProviderFromData(data, keycloakVersion)
if err != nil {
return diag.FromErr(err)
Expand Down
20 changes: 16 additions & 4 deletions provider/resource_keycloak_authentication_bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ func resetAuthenticationBindingsForRealm(realm *keycloak.Realm, keycloakVersion

func resourceKeycloakAuthenticationBindingsCreate(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics {
keycloakClient := meta.(*keycloak.KeycloakClient)
keycloakVersion := keycloakClient.Version()
keycloakVersion, err := keycloakClient.Version(ctx)
if err != nil {
return diag.FromErr(err)
}

realm, err := keycloakClient.GetRealm(ctx, data.Get("realm_id").(string))
if err != nil {
Expand Down Expand Up @@ -124,7 +127,10 @@ func resourceKeycloakAuthenticationBindingsCreate(ctx context.Context, data *sch

func resourceKeycloakAuthenticationBindingsRead(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics {
keycloakClient := meta.(*keycloak.KeycloakClient)
keycloakVersion := keycloakClient.Version()
keycloakVersion, err := keycloakClient.Version(ctx)
if err != nil {
return diag.FromErr(err)
}

realm, err := keycloakClient.GetRealm(ctx, data.Id())
if err != nil {
Expand All @@ -138,7 +144,10 @@ func resourceKeycloakAuthenticationBindingsRead(ctx context.Context, data *schem

func resourceKeycloakAuthenticationBindingsDelete(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics {
keycloakClient := meta.(*keycloak.KeycloakClient)
keycloakVersion := keycloakClient.Version()
keycloakVersion, err := keycloakClient.Version(ctx)
if err != nil {
return diag.FromErr(err)
}

realm, err := keycloakClient.GetRealm(ctx, data.Id())
if err != nil {
Expand All @@ -157,7 +166,10 @@ func resourceKeycloakAuthenticationBindingsDelete(ctx context.Context, data *sch

func resourceKeycloakAuthenticationBindingsUpdate(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics {
keycloakClient := meta.(*keycloak.KeycloakClient)
keycloakVersion := keycloakClient.Version()
keycloakVersion, err := keycloakClient.Version(ctx)
if err != nil {
return diag.FromErr(err)
}

realm, err := keycloakClient.GetRealm(ctx, data.Id())
if err != nil {
Expand Down
15 changes: 12 additions & 3 deletions provider/resource_keycloak_realm.go
Original file line number Diff line number Diff line change
Expand Up @@ -1394,7 +1394,10 @@ func getHeaderSettings(realm *keycloak.Realm) map[string]interface{} {

func resourceKeycloakRealmCreate(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics {
keycloakClient := meta.(*keycloak.KeycloakClient)
keycloakVersion := keycloakClient.Version()
keycloakVersion, err := keycloakClient.Version(ctx)
if err != nil {
return diag.FromErr(err)
}

realm, err := getRealmFromData(data, keycloakVersion)
if err != nil {
Expand Down Expand Up @@ -1423,7 +1426,10 @@ func resourceKeycloakRealmCreate(ctx context.Context, data *schema.ResourceData,

func resourceKeycloakRealmRead(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics {
keycloakClient := meta.(*keycloak.KeycloakClient)
keycloakVersion := keycloakClient.Version()
keycloakVersion, err := keycloakClient.Version(ctx)
if err != nil {
return diag.FromErr(err)
}

realm, err := keycloakClient.GetRealm(ctx, data.Id())
if err != nil {
Expand All @@ -1442,7 +1448,10 @@ func resourceKeycloakRealmRead(ctx context.Context, data *schema.ResourceData, m

func resourceKeycloakRealmUpdate(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics {
keycloakClient := meta.(*keycloak.KeycloakClient)
keycloakVersion := keycloakClient.Version()
keycloakVersion, err := keycloakClient.Version(ctx)
if err != nil {
return diag.FromErr(err)
}

realm, err := getRealmFromData(data, keycloakVersion)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion provider/resource_keycloak_realm_user_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func getRealmUserProfileAttributeFromData(m map[string]interface{}) *keycloak.Re
Group: m["group"].(string),
}

if v, ok := m["multivalued"].(bool); ok {
if v, ok := m["multi_valued"].(bool); ok {
attribute.MultiValued = v
} else {
attribute.MultiValued = false
Expand Down
11 changes: 10 additions & 1 deletion provider/resource_keycloak_realm_user_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,19 @@ func TestAccKeycloakRealmUserProfile_basicFull(t *testing.T) {

realmName := acctest.RandomWithPrefix("tf-acc")

mvSupported, err := keycloakClient.VersionIsGreaterThanOrEqualTo(testCtx, keycloak.Version_24)
if err != nil {
t.Errorf("error checking keycloak version: %v", err)
}

realmUserProfile := &keycloak.RealmUserProfile{
Attributes: []*keycloak.RealmUserProfileAttribute{
{Name: "username"}, {Name: "email"}, // Version >=23 needs these
{Name: "attribute1"},
{
Name: "attribute2",
DisplayName: "attribute 2",
MultiValued: false,
MultiValued: mvSupported,
Group: "group",
Selector: &keycloak.RealmUserProfileSelector{Scopes: []string{"roles"}},
Required: &keycloak.RealmUserProfileRequired{
Expand Down Expand Up @@ -545,6 +550,10 @@ resource "keycloak_realm_user_profile" "realm_user_profile" {
display_name = "{{ $attribute.DisplayName }}"
{{- end }}

{{- if $attribute.MultiValued }}
multi_valued = "{{ $attribute.MultiValued }}"
{{- end }}

{{- if $attribute.Group }}
group = "{{ $attribute.Group }}"
{{- end }}
Expand Down