1. Packages
  2. Keycloak
  3. API Docs
  4. GenericRoleMapper
Keycloak v5.3.1 published on Monday, Mar 11, 2024 by Pulumi

keycloak.GenericRoleMapper

Explore with Pulumi AI

keycloak logo
Keycloak v5.3.1 published on Monday, Mar 11, 2024 by Pulumi

    Allow for creating and managing a client’s or client scope’s role mappings within Keycloak.

    By default, all the user role mappings of the user are added as claims within the token (OIDC) or assertion (SAML). When full_scope_allowed is set to false for a client, role scope mapping allows you to limit the roles that get declared inside an access token for a client.

    Example Usage

    Realm Role To Client)

    import * as pulumi from "@pulumi/pulumi";
    import * as keycloak from "@pulumi/keycloak";
    
    const realm = new keycloak.Realm("realm", {
        realm: "my-realm",
        enabled: true,
    });
    const client = new keycloak.openid.Client("client", {
        realmId: realm.id,
        clientId: "client",
        enabled: true,
        accessType: "BEARER-ONLY",
    });
    const realmRole = new keycloak.Role("realmRole", {
        realmId: realm.id,
        description: "My Realm Role",
    });
    const clientRoleMapper = new keycloak.GenericRoleMapper("clientRoleMapper", {
        realmId: realm.id,
        clientId: client.id,
        roleId: realmRole.id,
    });
    
    import pulumi
    import pulumi_keycloak as keycloak
    
    realm = keycloak.Realm("realm",
        realm="my-realm",
        enabled=True)
    client = keycloak.openid.Client("client",
        realm_id=realm.id,
        client_id="client",
        enabled=True,
        access_type="BEARER-ONLY")
    realm_role = keycloak.Role("realmRole",
        realm_id=realm.id,
        description="My Realm Role")
    client_role_mapper = keycloak.GenericRoleMapper("clientRoleMapper",
        realm_id=realm.id,
        client_id=client.id,
        role_id=realm_role.id)
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-keycloak/sdk/v5/go/keycloak"
    	"github.com/pulumi/pulumi-keycloak/sdk/v5/go/keycloak/openid"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		realm, err := keycloak.NewRealm(ctx, "realm", &keycloak.RealmArgs{
    			Realm:   pulumi.String("my-realm"),
    			Enabled: pulumi.Bool(true),
    		})
    		if err != nil {
    			return err
    		}
    		client, err := openid.NewClient(ctx, "client", &openid.ClientArgs{
    			RealmId:    realm.ID(),
    			ClientId:   pulumi.String("client"),
    			Enabled:    pulumi.Bool(true),
    			AccessType: pulumi.String("BEARER-ONLY"),
    		})
    		if err != nil {
    			return err
    		}
    		realmRole, err := keycloak.NewRole(ctx, "realmRole", &keycloak.RoleArgs{
    			RealmId:     realm.ID(),
    			Description: pulumi.String("My Realm Role"),
    		})
    		if err != nil {
    			return err
    		}
    		_, err = keycloak.NewGenericRoleMapper(ctx, "clientRoleMapper", &keycloak.GenericRoleMapperArgs{
    			RealmId:  realm.ID(),
    			ClientId: client.ID(),
    			RoleId:   realmRole.ID(),
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Keycloak = Pulumi.Keycloak;
    
    return await Deployment.RunAsync(() => 
    {
        var realm = new Keycloak.Realm("realm", new()
        {
            RealmName = "my-realm",
            Enabled = true,
        });
    
        var client = new Keycloak.OpenId.Client("client", new()
        {
            RealmId = realm.Id,
            ClientId = "client",
            Enabled = true,
            AccessType = "BEARER-ONLY",
        });
    
        var realmRole = new Keycloak.Role("realmRole", new()
        {
            RealmId = realm.Id,
            Description = "My Realm Role",
        });
    
        var clientRoleMapper = new Keycloak.GenericRoleMapper("clientRoleMapper", new()
        {
            RealmId = realm.Id,
            ClientId = client.Id,
            RoleId = realmRole.Id,
        });
    
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.keycloak.Realm;
    import com.pulumi.keycloak.RealmArgs;
    import com.pulumi.keycloak.openid.Client;
    import com.pulumi.keycloak.openid.ClientArgs;
    import com.pulumi.keycloak.Role;
    import com.pulumi.keycloak.RoleArgs;
    import com.pulumi.keycloak.GenericRoleMapper;
    import com.pulumi.keycloak.GenericRoleMapperArgs;
    import java.util.List;
    import java.util.ArrayList;
    import java.util.Map;
    import java.io.File;
    import java.nio.file.Files;
    import java.nio.file.Paths;
    
    public class App {
        public static void main(String[] args) {
            Pulumi.run(App::stack);
        }
    
        public static void stack(Context ctx) {
            var realm = new Realm("realm", RealmArgs.builder()        
                .realm("my-realm")
                .enabled(true)
                .build());
    
            var client = new Client("client", ClientArgs.builder()        
                .realmId(realm.id())
                .clientId("client")
                .enabled(true)
                .accessType("BEARER-ONLY")
                .build());
    
            var realmRole = new Role("realmRole", RoleArgs.builder()        
                .realmId(realm.id())
                .description("My Realm Role")
                .build());
    
            var clientRoleMapper = new GenericRoleMapper("clientRoleMapper", GenericRoleMapperArgs.builder()        
                .realmId(realm.id())
                .clientId(client.id())
                .roleId(realmRole.id())
                .build());
    
        }
    }
    
    resources:
      realm:
        type: keycloak:Realm
        properties:
          realm: my-realm
          enabled: true
      client:
        type: keycloak:openid:Client
        properties:
          realmId: ${realm.id}
          clientId: client
          enabled: true
          accessType: BEARER-ONLY
      realmRole:
        type: keycloak:Role
        properties:
          realmId: ${realm.id}
          description: My Realm Role
      clientRoleMapper:
        type: keycloak:GenericRoleMapper
        properties:
          realmId: ${realm.id}
          clientId: ${client.id}
          roleId: ${realmRole.id}
    

    Client Role To Client)

    import * as pulumi from "@pulumi/pulumi";
    import * as keycloak from "@pulumi/keycloak";
    
    const realm = new keycloak.Realm("realm", {
        realm: "my-realm",
        enabled: true,
    });
    const clientA = new keycloak.openid.Client("clientA", {
        realmId: realm.id,
        clientId: "client-a",
        enabled: true,
        accessType: "BEARER-ONLY",
        fullScopeAllowed: false,
    });
    const clientRoleA = new keycloak.Role("clientRoleA", {
        realmId: realm.id,
        clientId: clientA.id,
        description: "My Client Role",
    });
    const clientB = new keycloak.openid.Client("clientB", {
        realmId: realm.id,
        clientId: "client-b",
        enabled: true,
        accessType: "BEARER-ONLY",
    });
    const clientRoleB = new keycloak.Role("clientRoleB", {
        realmId: realm.id,
        clientId: clientB.id,
        description: "My Client Role",
    });
    const clientBRoleMapper = new keycloak.GenericRoleMapper("clientBRoleMapper", {
        realmId: realm.id,
        clientId: clientB.id,
        roleId: clientRoleA.id,
    });
    
    import pulumi
    import pulumi_keycloak as keycloak
    
    realm = keycloak.Realm("realm",
        realm="my-realm",
        enabled=True)
    client_a = keycloak.openid.Client("clientA",
        realm_id=realm.id,
        client_id="client-a",
        enabled=True,
        access_type="BEARER-ONLY",
        full_scope_allowed=False)
    client_role_a = keycloak.Role("clientRoleA",
        realm_id=realm.id,
        client_id=client_a.id,
        description="My Client Role")
    client_b = keycloak.openid.Client("clientB",
        realm_id=realm.id,
        client_id="client-b",
        enabled=True,
        access_type="BEARER-ONLY")
    client_role_b = keycloak.Role("clientRoleB",
        realm_id=realm.id,
        client_id=client_b.id,
        description="My Client Role")
    client_b_role_mapper = keycloak.GenericRoleMapper("clientBRoleMapper",
        realm_id=realm.id,
        client_id=client_b.id,
        role_id=client_role_a.id)
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-keycloak/sdk/v5/go/keycloak"
    	"github.com/pulumi/pulumi-keycloak/sdk/v5/go/keycloak/openid"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		realm, err := keycloak.NewRealm(ctx, "realm", &keycloak.RealmArgs{
    			Realm:   pulumi.String("my-realm"),
    			Enabled: pulumi.Bool(true),
    		})
    		if err != nil {
    			return err
    		}
    		clientA, err := openid.NewClient(ctx, "clientA", &openid.ClientArgs{
    			RealmId:          realm.ID(),
    			ClientId:         pulumi.String("client-a"),
    			Enabled:          pulumi.Bool(true),
    			AccessType:       pulumi.String("BEARER-ONLY"),
    			FullScopeAllowed: pulumi.Bool(false),
    		})
    		if err != nil {
    			return err
    		}
    		clientRoleA, err := keycloak.NewRole(ctx, "clientRoleA", &keycloak.RoleArgs{
    			RealmId:     realm.ID(),
    			ClientId:    clientA.ID(),
    			Description: pulumi.String("My Client Role"),
    		})
    		if err != nil {
    			return err
    		}
    		clientB, err := openid.NewClient(ctx, "clientB", &openid.ClientArgs{
    			RealmId:    realm.ID(),
    			ClientId:   pulumi.String("client-b"),
    			Enabled:    pulumi.Bool(true),
    			AccessType: pulumi.String("BEARER-ONLY"),
    		})
    		if err != nil {
    			return err
    		}
    		_, err = keycloak.NewRole(ctx, "clientRoleB", &keycloak.RoleArgs{
    			RealmId:     realm.ID(),
    			ClientId:    clientB.ID(),
    			Description: pulumi.String("My Client Role"),
    		})
    		if err != nil {
    			return err
    		}
    		_, err = keycloak.NewGenericRoleMapper(ctx, "clientBRoleMapper", &keycloak.GenericRoleMapperArgs{
    			RealmId:  realm.ID(),
    			ClientId: clientB.ID(),
    			RoleId:   clientRoleA.ID(),
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Keycloak = Pulumi.Keycloak;
    
    return await Deployment.RunAsync(() => 
    {
        var realm = new Keycloak.Realm("realm", new()
        {
            RealmName = "my-realm",
            Enabled = true,
        });
    
        var clientA = new Keycloak.OpenId.Client("clientA", new()
        {
            RealmId = realm.Id,
            ClientId = "client-a",
            Enabled = true,
            AccessType = "BEARER-ONLY",
            FullScopeAllowed = false,
        });
    
        var clientRoleA = new Keycloak.Role("clientRoleA", new()
        {
            RealmId = realm.Id,
            ClientId = clientA.Id,
            Description = "My Client Role",
        });
    
        var clientB = new Keycloak.OpenId.Client("clientB", new()
        {
            RealmId = realm.Id,
            ClientId = "client-b",
            Enabled = true,
            AccessType = "BEARER-ONLY",
        });
    
        var clientRoleB = new Keycloak.Role("clientRoleB", new()
        {
            RealmId = realm.Id,
            ClientId = clientB.Id,
            Description = "My Client Role",
        });
    
        var clientBRoleMapper = new Keycloak.GenericRoleMapper("clientBRoleMapper", new()
        {
            RealmId = realm.Id,
            ClientId = clientB.Id,
            RoleId = clientRoleA.Id,
        });
    
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.keycloak.Realm;
    import com.pulumi.keycloak.RealmArgs;
    import com.pulumi.keycloak.openid.Client;
    import com.pulumi.keycloak.openid.ClientArgs;
    import com.pulumi.keycloak.Role;
    import com.pulumi.keycloak.RoleArgs;
    import com.pulumi.keycloak.GenericRoleMapper;
    import com.pulumi.keycloak.GenericRoleMapperArgs;
    import java.util.List;
    import java.util.ArrayList;
    import java.util.Map;
    import java.io.File;
    import java.nio.file.Files;
    import java.nio.file.Paths;
    
    public class App {
        public static void main(String[] args) {
            Pulumi.run(App::stack);
        }
    
        public static void stack(Context ctx) {
            var realm = new Realm("realm", RealmArgs.builder()        
                .realm("my-realm")
                .enabled(true)
                .build());
    
            var clientA = new Client("clientA", ClientArgs.builder()        
                .realmId(realm.id())
                .clientId("client-a")
                .enabled(true)
                .accessType("BEARER-ONLY")
                .fullScopeAllowed(false)
                .build());
    
            var clientRoleA = new Role("clientRoleA", RoleArgs.builder()        
                .realmId(realm.id())
                .clientId(clientA.id())
                .description("My Client Role")
                .build());
    
            var clientB = new Client("clientB", ClientArgs.builder()        
                .realmId(realm.id())
                .clientId("client-b")
                .enabled(true)
                .accessType("BEARER-ONLY")
                .build());
    
            var clientRoleB = new Role("clientRoleB", RoleArgs.builder()        
                .realmId(realm.id())
                .clientId(clientB.id())
                .description("My Client Role")
                .build());
    
            var clientBRoleMapper = new GenericRoleMapper("clientBRoleMapper", GenericRoleMapperArgs.builder()        
                .realmId(realm.id())
                .clientId(clientB.id())
                .roleId(clientRoleA.id())
                .build());
    
        }
    }
    
    resources:
      realm:
        type: keycloak:Realm
        properties:
          realm: my-realm
          enabled: true
      clientA:
        type: keycloak:openid:Client
        properties:
          realmId: ${realm.id}
          clientId: client-a
          enabled: true
          accessType: BEARER-ONLY
          # disable full scope, roles are assigned via keycloak_generic_role_mapper
          fullScopeAllowed: false
      clientRoleA:
        type: keycloak:Role
        properties:
          realmId: ${realm.id}
          clientId: ${clientA.id}
          description: My Client Role
      clientB:
        type: keycloak:openid:Client
        properties:
          realmId: ${realm.id}
          clientId: client-b
          enabled: true
          accessType: BEARER-ONLY
      clientRoleB:
        type: keycloak:Role
        properties:
          realmId: ${realm.id}
          clientId: ${clientB.id}
          description: My Client Role
      clientBRoleMapper:
        type: keycloak:GenericRoleMapper
        properties:
          realmId: ${realm.id}
          clientId: ${clientB.id}
          roleId: ${clientRoleA.id}
    

    Realm Role To Client Scope)

    import * as pulumi from "@pulumi/pulumi";
    import * as keycloak from "@pulumi/keycloak";
    
    const realm = new keycloak.Realm("realm", {
        realm: "my-realm",
        enabled: true,
    });
    const clientScope = new keycloak.openid.ClientScope("clientScope", {realmId: realm.id});
    const realmRole = new keycloak.Role("realmRole", {
        realmId: realm.id,
        description: "My Realm Role",
    });
    const clientRoleMapper = new keycloak.GenericRoleMapper("clientRoleMapper", {
        realmId: realm.id,
        clientScopeId: clientScope.id,
        roleId: realmRole.id,
    });
    
    import pulumi
    import pulumi_keycloak as keycloak
    
    realm = keycloak.Realm("realm",
        realm="my-realm",
        enabled=True)
    client_scope = keycloak.openid.ClientScope("clientScope", realm_id=realm.id)
    realm_role = keycloak.Role("realmRole",
        realm_id=realm.id,
        description="My Realm Role")
    client_role_mapper = keycloak.GenericRoleMapper("clientRoleMapper",
        realm_id=realm.id,
        client_scope_id=client_scope.id,
        role_id=realm_role.id)
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-keycloak/sdk/v5/go/keycloak"
    	"github.com/pulumi/pulumi-keycloak/sdk/v5/go/keycloak/openid"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		realm, err := keycloak.NewRealm(ctx, "realm", &keycloak.RealmArgs{
    			Realm:   pulumi.String("my-realm"),
    			Enabled: pulumi.Bool(true),
    		})
    		if err != nil {
    			return err
    		}
    		clientScope, err := openid.NewClientScope(ctx, "clientScope", &openid.ClientScopeArgs{
    			RealmId: realm.ID(),
    		})
    		if err != nil {
    			return err
    		}
    		realmRole, err := keycloak.NewRole(ctx, "realmRole", &keycloak.RoleArgs{
    			RealmId:     realm.ID(),
    			Description: pulumi.String("My Realm Role"),
    		})
    		if err != nil {
    			return err
    		}
    		_, err = keycloak.NewGenericRoleMapper(ctx, "clientRoleMapper", &keycloak.GenericRoleMapperArgs{
    			RealmId:       realm.ID(),
    			ClientScopeId: clientScope.ID(),
    			RoleId:        realmRole.ID(),
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Keycloak = Pulumi.Keycloak;
    
    return await Deployment.RunAsync(() => 
    {
        var realm = new Keycloak.Realm("realm", new()
        {
            RealmName = "my-realm",
            Enabled = true,
        });
    
        var clientScope = new Keycloak.OpenId.ClientScope("clientScope", new()
        {
            RealmId = realm.Id,
        });
    
        var realmRole = new Keycloak.Role("realmRole", new()
        {
            RealmId = realm.Id,
            Description = "My Realm Role",
        });
    
        var clientRoleMapper = new Keycloak.GenericRoleMapper("clientRoleMapper", new()
        {
            RealmId = realm.Id,
            ClientScopeId = clientScope.Id,
            RoleId = realmRole.Id,
        });
    
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.keycloak.Realm;
    import com.pulumi.keycloak.RealmArgs;
    import com.pulumi.keycloak.openid.ClientScope;
    import com.pulumi.keycloak.openid.ClientScopeArgs;
    import com.pulumi.keycloak.Role;
    import com.pulumi.keycloak.RoleArgs;
    import com.pulumi.keycloak.GenericRoleMapper;
    import com.pulumi.keycloak.GenericRoleMapperArgs;
    import java.util.List;
    import java.util.ArrayList;
    import java.util.Map;
    import java.io.File;
    import java.nio.file.Files;
    import java.nio.file.Paths;
    
    public class App {
        public static void main(String[] args) {
            Pulumi.run(App::stack);
        }
    
        public static void stack(Context ctx) {
            var realm = new Realm("realm", RealmArgs.builder()        
                .realm("my-realm")
                .enabled(true)
                .build());
    
            var clientScope = new ClientScope("clientScope", ClientScopeArgs.builder()        
                .realmId(realm.id())
                .build());
    
            var realmRole = new Role("realmRole", RoleArgs.builder()        
                .realmId(realm.id())
                .description("My Realm Role")
                .build());
    
            var clientRoleMapper = new GenericRoleMapper("clientRoleMapper", GenericRoleMapperArgs.builder()        
                .realmId(realm.id())
                .clientScopeId(clientScope.id())
                .roleId(realmRole.id())
                .build());
    
        }
    }
    
    resources:
      realm:
        type: keycloak:Realm
        properties:
          realm: my-realm
          enabled: true
      clientScope:
        type: keycloak:openid:ClientScope
        properties:
          realmId: ${realm.id}
      realmRole:
        type: keycloak:Role
        properties:
          realmId: ${realm.id}
          description: My Realm Role
      clientRoleMapper:
        type: keycloak:GenericRoleMapper
        properties:
          realmId: ${realm.id}
          clientScopeId: ${clientScope.id}
          roleId: ${realmRole.id}
    

    Client Role To Client Scope)

    import * as pulumi from "@pulumi/pulumi";
    import * as keycloak from "@pulumi/keycloak";
    
    const realm = new keycloak.Realm("realm", {
        realm: "my-realm",
        enabled: true,
    });
    const client = new keycloak.openid.Client("client", {
        realmId: realm.id,
        clientId: "client",
        enabled: true,
        accessType: "BEARER-ONLY",
    });
    const clientRole = new keycloak.Role("clientRole", {
        realmId: realm.id,
        clientId: client.id,
        description: "My Client Role",
    });
    const clientScope = new keycloak.openid.ClientScope("clientScope", {realmId: realm.id});
    const clientBRoleMapper = new keycloak.GenericRoleMapper("clientBRoleMapper", {
        realmId: realm.id,
        clientScopeId: clientScope.id,
        roleId: clientRole.id,
    });
    
    import pulumi
    import pulumi_keycloak as keycloak
    
    realm = keycloak.Realm("realm",
        realm="my-realm",
        enabled=True)
    client = keycloak.openid.Client("client",
        realm_id=realm.id,
        client_id="client",
        enabled=True,
        access_type="BEARER-ONLY")
    client_role = keycloak.Role("clientRole",
        realm_id=realm.id,
        client_id=client.id,
        description="My Client Role")
    client_scope = keycloak.openid.ClientScope("clientScope", realm_id=realm.id)
    client_b_role_mapper = keycloak.GenericRoleMapper("clientBRoleMapper",
        realm_id=realm.id,
        client_scope_id=client_scope.id,
        role_id=client_role.id)
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-keycloak/sdk/v5/go/keycloak"
    	"github.com/pulumi/pulumi-keycloak/sdk/v5/go/keycloak/openid"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		realm, err := keycloak.NewRealm(ctx, "realm", &keycloak.RealmArgs{
    			Realm:   pulumi.String("my-realm"),
    			Enabled: pulumi.Bool(true),
    		})
    		if err != nil {
    			return err
    		}
    		client, err := openid.NewClient(ctx, "client", &openid.ClientArgs{
    			RealmId:    realm.ID(),
    			ClientId:   pulumi.String("client"),
    			Enabled:    pulumi.Bool(true),
    			AccessType: pulumi.String("BEARER-ONLY"),
    		})
    		if err != nil {
    			return err
    		}
    		clientRole, err := keycloak.NewRole(ctx, "clientRole", &keycloak.RoleArgs{
    			RealmId:     realm.ID(),
    			ClientId:    client.ID(),
    			Description: pulumi.String("My Client Role"),
    		})
    		if err != nil {
    			return err
    		}
    		clientScope, err := openid.NewClientScope(ctx, "clientScope", &openid.ClientScopeArgs{
    			RealmId: realm.ID(),
    		})
    		if err != nil {
    			return err
    		}
    		_, err = keycloak.NewGenericRoleMapper(ctx, "clientBRoleMapper", &keycloak.GenericRoleMapperArgs{
    			RealmId:       realm.ID(),
    			ClientScopeId: clientScope.ID(),
    			RoleId:        clientRole.ID(),
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Keycloak = Pulumi.Keycloak;
    
    return await Deployment.RunAsync(() => 
    {
        var realm = new Keycloak.Realm("realm", new()
        {
            RealmName = "my-realm",
            Enabled = true,
        });
    
        var client = new Keycloak.OpenId.Client("client", new()
        {
            RealmId = realm.Id,
            ClientId = "client",
            Enabled = true,
            AccessType = "BEARER-ONLY",
        });
    
        var clientRole = new Keycloak.Role("clientRole", new()
        {
            RealmId = realm.Id,
            ClientId = client.Id,
            Description = "My Client Role",
        });
    
        var clientScope = new Keycloak.OpenId.ClientScope("clientScope", new()
        {
            RealmId = realm.Id,
        });
    
        var clientBRoleMapper = new Keycloak.GenericRoleMapper("clientBRoleMapper", new()
        {
            RealmId = realm.Id,
            ClientScopeId = clientScope.Id,
            RoleId = clientRole.Id,
        });
    
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.keycloak.Realm;
    import com.pulumi.keycloak.RealmArgs;
    import com.pulumi.keycloak.openid.Client;
    import com.pulumi.keycloak.openid.ClientArgs;
    import com.pulumi.keycloak.Role;
    import com.pulumi.keycloak.RoleArgs;
    import com.pulumi.keycloak.openid.ClientScope;
    import com.pulumi.keycloak.openid.ClientScopeArgs;
    import com.pulumi.keycloak.GenericRoleMapper;
    import com.pulumi.keycloak.GenericRoleMapperArgs;
    import java.util.List;
    import java.util.ArrayList;
    import java.util.Map;
    import java.io.File;
    import java.nio.file.Files;
    import java.nio.file.Paths;
    
    public class App {
        public static void main(String[] args) {
            Pulumi.run(App::stack);
        }
    
        public static void stack(Context ctx) {
            var realm = new Realm("realm", RealmArgs.builder()        
                .realm("my-realm")
                .enabled(true)
                .build());
    
            var client = new Client("client", ClientArgs.builder()        
                .realmId(realm.id())
                .clientId("client")
                .enabled(true)
                .accessType("BEARER-ONLY")
                .build());
    
            var clientRole = new Role("clientRole", RoleArgs.builder()        
                .realmId(realm.id())
                .clientId(client.id())
                .description("My Client Role")
                .build());
    
            var clientScope = new ClientScope("clientScope", ClientScopeArgs.builder()        
                .realmId(realm.id())
                .build());
    
            var clientBRoleMapper = new GenericRoleMapper("clientBRoleMapper", GenericRoleMapperArgs.builder()        
                .realmId(realm.id())
                .clientScopeId(clientScope.id())
                .roleId(clientRole.id())
                .build());
    
        }
    }
    
    resources:
      realm:
        type: keycloak:Realm
        properties:
          realm: my-realm
          enabled: true
      client:
        type: keycloak:openid:Client
        properties:
          realmId: ${realm.id}
          clientId: client
          enabled: true
          accessType: BEARER-ONLY
      clientRole:
        type: keycloak:Role
        properties:
          realmId: ${realm.id}
          clientId: ${client.id}
          description: My Client Role
      clientScope:
        type: keycloak:openid:ClientScope
        properties:
          realmId: ${realm.id}
      clientBRoleMapper:
        type: keycloak:GenericRoleMapper
        properties:
          realmId: ${realm.id}
          clientScopeId: ${clientScope.id}
          roleId: ${clientRole.id}
    

    Create GenericRoleMapper Resource

    Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.

    Constructor syntax

    new GenericRoleMapper(name: string, args: GenericRoleMapperArgs, opts?: CustomResourceOptions);
    @overload
    def GenericRoleMapper(resource_name: str,
                          args: GenericRoleMapperArgs,
                          opts: Optional[ResourceOptions] = None)
    
    @overload
    def GenericRoleMapper(resource_name: str,
                          opts: Optional[ResourceOptions] = None,
                          realm_id: Optional[str] = None,
                          role_id: Optional[str] = None,
                          client_id: Optional[str] = None,
                          client_scope_id: Optional[str] = None)
    func NewGenericRoleMapper(ctx *Context, name string, args GenericRoleMapperArgs, opts ...ResourceOption) (*GenericRoleMapper, error)
    public GenericRoleMapper(string name, GenericRoleMapperArgs args, CustomResourceOptions? opts = null)
    public GenericRoleMapper(String name, GenericRoleMapperArgs args)
    public GenericRoleMapper(String name, GenericRoleMapperArgs args, CustomResourceOptions options)
    
    type: keycloak:GenericRoleMapper
    properties: # The arguments to resource properties.
    options: # Bag of options to control resource's behavior.
    
    

    Parameters

    name string
    The unique name of the resource.
    args GenericRoleMapperArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    resource_name str
    The unique name of the resource.
    args GenericRoleMapperArgs
    The arguments to resource properties.
    opts ResourceOptions
    Bag of options to control resource's behavior.
    ctx Context
    Context object for the current deployment.
    name string
    The unique name of the resource.
    args GenericRoleMapperArgs
    The arguments to resource properties.
    opts ResourceOption
    Bag of options to control resource's behavior.
    name string
    The unique name of the resource.
    args GenericRoleMapperArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    name String
    The unique name of the resource.
    args GenericRoleMapperArgs
    The arguments to resource properties.
    options CustomResourceOptions
    Bag of options to control resource's behavior.

    Example

    The following reference example uses placeholder values for all input properties.

    var genericRoleMapperResource = new Keycloak.GenericRoleMapper("genericRoleMapperResource", new()
    {
        RealmId = "string",
        RoleId = "string",
        ClientId = "string",
        ClientScopeId = "string",
    });
    
    example, err := keycloak.NewGenericRoleMapper(ctx, "genericRoleMapperResource", &keycloak.GenericRoleMapperArgs{
    	RealmId:       pulumi.String("string"),
    	RoleId:        pulumi.String("string"),
    	ClientId:      pulumi.String("string"),
    	ClientScopeId: pulumi.String("string"),
    })
    
    var genericRoleMapperResource = new GenericRoleMapper("genericRoleMapperResource", GenericRoleMapperArgs.builder()        
        .realmId("string")
        .roleId("string")
        .clientId("string")
        .clientScopeId("string")
        .build());
    
    generic_role_mapper_resource = keycloak.GenericRoleMapper("genericRoleMapperResource",
        realm_id="string",
        role_id="string",
        client_id="string",
        client_scope_id="string")
    
    const genericRoleMapperResource = new keycloak.GenericRoleMapper("genericRoleMapperResource", {
        realmId: "string",
        roleId: "string",
        clientId: "string",
        clientScopeId: "string",
    });
    
    type: keycloak:GenericRoleMapper
    properties:
        clientId: string
        clientScopeId: string
        realmId: string
        roleId: string
    

    GenericRoleMapper Resource Properties

    To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

    Inputs

    The GenericRoleMapper resource accepts the following input properties:

    RealmId string
    The realm this role mapper exists within.
    RoleId string
    The ID of the role to be added to this role mapper.
    ClientId string
    The ID of the client this role mapper should be added to. Conflicts with client_scope_id. This argument is required if client_scope_id is not set.
    ClientScopeId string
    The ID of the client scope this role mapper should be added to. Conflicts with client_id. This argument is required if client_id is not set.
    RealmId string
    The realm this role mapper exists within.
    RoleId string
    The ID of the role to be added to this role mapper.
    ClientId string
    The ID of the client this role mapper should be added to. Conflicts with client_scope_id. This argument is required if client_scope_id is not set.
    ClientScopeId string
    The ID of the client scope this role mapper should be added to. Conflicts with client_id. This argument is required if client_id is not set.
    realmId String
    The realm this role mapper exists within.
    roleId String
    The ID of the role to be added to this role mapper.
    clientId String
    The ID of the client this role mapper should be added to. Conflicts with client_scope_id. This argument is required if client_scope_id is not set.
    clientScopeId String
    The ID of the client scope this role mapper should be added to. Conflicts with client_id. This argument is required if client_id is not set.
    realmId string
    The realm this role mapper exists within.
    roleId string
    The ID of the role to be added to this role mapper.
    clientId string
    The ID of the client this role mapper should be added to. Conflicts with client_scope_id. This argument is required if client_scope_id is not set.
    clientScopeId string
    The ID of the client scope this role mapper should be added to. Conflicts with client_id. This argument is required if client_id is not set.
    realm_id str
    The realm this role mapper exists within.
    role_id str
    The ID of the role to be added to this role mapper.
    client_id str
    The ID of the client this role mapper should be added to. Conflicts with client_scope_id. This argument is required if client_scope_id is not set.
    client_scope_id str
    The ID of the client scope this role mapper should be added to. Conflicts with client_id. This argument is required if client_id is not set.
    realmId String
    The realm this role mapper exists within.
    roleId String
    The ID of the role to be added to this role mapper.
    clientId String
    The ID of the client this role mapper should be added to. Conflicts with client_scope_id. This argument is required if client_scope_id is not set.
    clientScopeId String
    The ID of the client scope this role mapper should be added to. Conflicts with client_id. This argument is required if client_id is not set.

    Outputs

    All input properties are implicitly available as output properties. Additionally, the GenericRoleMapper resource produces the following output properties:

    Id string
    The provider-assigned unique ID for this managed resource.
    Id string
    The provider-assigned unique ID for this managed resource.
    id String
    The provider-assigned unique ID for this managed resource.
    id string
    The provider-assigned unique ID for this managed resource.
    id str
    The provider-assigned unique ID for this managed resource.
    id String
    The provider-assigned unique ID for this managed resource.

    Look up Existing GenericRoleMapper Resource

    Get an existing GenericRoleMapper resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.

    public static get(name: string, id: Input<ID>, state?: GenericRoleMapperState, opts?: CustomResourceOptions): GenericRoleMapper
    @staticmethod
    def get(resource_name: str,
            id: str,
            opts: Optional[ResourceOptions] = None,
            client_id: Optional[str] = None,
            client_scope_id: Optional[str] = None,
            realm_id: Optional[str] = None,
            role_id: Optional[str] = None) -> GenericRoleMapper
    func GetGenericRoleMapper(ctx *Context, name string, id IDInput, state *GenericRoleMapperState, opts ...ResourceOption) (*GenericRoleMapper, error)
    public static GenericRoleMapper Get(string name, Input<string> id, GenericRoleMapperState? state, CustomResourceOptions? opts = null)
    public static GenericRoleMapper get(String name, Output<String> id, GenericRoleMapperState state, CustomResourceOptions options)
    Resource lookup is not supported in YAML
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    resource_name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    The following state arguments are supported:
    ClientId string
    The ID of the client this role mapper should be added to. Conflicts with client_scope_id. This argument is required if client_scope_id is not set.
    ClientScopeId string
    The ID of the client scope this role mapper should be added to. Conflicts with client_id. This argument is required if client_id is not set.
    RealmId string
    The realm this role mapper exists within.
    RoleId string
    The ID of the role to be added to this role mapper.
    ClientId string
    The ID of the client this role mapper should be added to. Conflicts with client_scope_id. This argument is required if client_scope_id is not set.
    ClientScopeId string
    The ID of the client scope this role mapper should be added to. Conflicts with client_id. This argument is required if client_id is not set.
    RealmId string
    The realm this role mapper exists within.
    RoleId string
    The ID of the role to be added to this role mapper.
    clientId String
    The ID of the client this role mapper should be added to. Conflicts with client_scope_id. This argument is required if client_scope_id is not set.
    clientScopeId String
    The ID of the client scope this role mapper should be added to. Conflicts with client_id. This argument is required if client_id is not set.
    realmId String
    The realm this role mapper exists within.
    roleId String
    The ID of the role to be added to this role mapper.
    clientId string
    The ID of the client this role mapper should be added to. Conflicts with client_scope_id. This argument is required if client_scope_id is not set.
    clientScopeId string
    The ID of the client scope this role mapper should be added to. Conflicts with client_id. This argument is required if client_id is not set.
    realmId string
    The realm this role mapper exists within.
    roleId string
    The ID of the role to be added to this role mapper.
    client_id str
    The ID of the client this role mapper should be added to. Conflicts with client_scope_id. This argument is required if client_scope_id is not set.
    client_scope_id str
    The ID of the client scope this role mapper should be added to. Conflicts with client_id. This argument is required if client_id is not set.
    realm_id str
    The realm this role mapper exists within.
    role_id str
    The ID of the role to be added to this role mapper.
    clientId String
    The ID of the client this role mapper should be added to. Conflicts with client_scope_id. This argument is required if client_scope_id is not set.
    clientScopeId String
    The ID of the client scope this role mapper should be added to. Conflicts with client_id. This argument is required if client_id is not set.
    realmId String
    The realm this role mapper exists within.
    roleId String
    The ID of the role to be added to this role mapper.

    Import

    Generic client role mappers can be imported using one of the following two formats:

    • When mapping a role to a client, use the format {{realmId}}/client/{{clientId}}/scope-mappings/{{roleClientId}}/{{roleId}}

    • When mapping a role to a client scope, use the format {{realmId}}/client-scope/{{clientScopeId}}/scope-mappings/{{roleClientId}}/{{roleId}}

    Example:

    bash

    $ pulumi import keycloak:index/genericRoleMapper:GenericRoleMapper client_role_mapper my-realm/client/23888550-5dcd-41f6-85ba-554233021e9c/scope-mappings/ce51f004-bdfb-4dd5-a963-c4487d2dec5b/ff3aa49f-bc07-4030-8783-41918c3614a3
    

    To learn more about importing existing cloud resources, see Importing resources.

    Package Details

    Repository
    Keycloak pulumi/pulumi-keycloak
    License
    Apache-2.0
    Notes
    This Pulumi package is based on the keycloak Terraform Provider.
    keycloak logo
    Keycloak v5.3.1 published on Monday, Mar 11, 2024 by Pulumi