Skip to content

Commit

Permalink
fix: avoid validation errors during plan for missing realm and openid…
Browse files Browse the repository at this point in the history
… client resources (#841)
  • Loading branch information
kherock authored Jun 8, 2023
1 parent b6060a0 commit bac7360
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
4 changes: 1 addition & 3 deletions keycloak/openid_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,7 @@ func (keycloakClient *KeycloakClient) getOpenidClientScopes(ctx context.Context,
var scopes []*OpenidClientScope

err := keycloakClient.get(ctx, fmt.Sprintf("/realms/%s/clients/%s/%s-client-scopes", realmId, clientId, t), &scopes, nil)
if err != nil && ErrorIs404(err) {
return nil, fmt.Errorf("validation error: client with id %s does not exist", clientId)
} else if err != nil {
if err != nil {
return nil, err
}

Expand Down
2 changes: 1 addition & 1 deletion provider/resource_keycloak_generic_role_mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func resourceKeycloakGenericRoleMapperRead(ctx context.Context, data *schema.Res

role, err := keycloakClient.GetRole(ctx, realmId, roleId)
if err != nil {
return diag.FromErr(err)
return handleNotFoundError(ctx, err, data)
}

mappedRole, err := keycloakClient.GetRoleScopeMapping(ctx, realmId, clientId, clientScopeId, role)
Expand Down
4 changes: 4 additions & 0 deletions provider/resource_keycloak_openid_client_default_scopes.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package provider
import (
"context"
"fmt"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/mrparkers/terraform-provider-keycloak/keycloak"
Expand Down Expand Up @@ -70,6 +71,9 @@ func resourceKeycloakOpenidClientDefaultScopesReconcile(ctx context.Context, dat

keycloakOpenidClientDefaultScopes, err := keycloakClient.GetOpenidClientDefaultScopes(ctx, realmId, clientId)
if err != nil {
if keycloak.ErrorIs404(err) {
return diag.FromErr(fmt.Errorf("validation error: client with id %s does not exist", clientId))
}
return diag.FromErr(err)
}

Expand Down
4 changes: 4 additions & 0 deletions provider/resource_keycloak_openid_client_optional_scopes.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package provider
import (
"context"
"fmt"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/mrparkers/terraform-provider-keycloak/keycloak"
Expand Down Expand Up @@ -70,6 +71,9 @@ func resourceKeycloakOpenidClientOptionalScopesReconcile(ctx context.Context, da

keycloakOpenidClientOptionalScopes, err := keycloakClient.GetOpenidClientOptionalScopes(ctx, realmId, clientId)
if err != nil {
if keycloak.ErrorIs404(err) {
return diag.FromErr(fmt.Errorf("validation error: client with id %s does not exist", clientId))
}
return diag.FromErr(err)
}

Expand Down

0 comments on commit bac7360

Please sign in to comment.