keycloak.Role
Explore with Pulumi AI
Allows for creating and managing roles within Keycloak.
Roles allow you to define privileges within Keycloak and map them to users and groups.
Example Usage
Realm Role)
import * as pulumi from "@pulumi/pulumi";
import * as keycloak from "@pulumi/keycloak";
const realm = new keycloak.Realm("realm", {
    realm: "my-realm",
    enabled: true,
});
const realmRole = new keycloak.Role("realm_role", {
    realmId: realm.id,
    name: "my-realm-role",
    description: "My Realm Role",
    attributes: {
        key: "value",
        multivalue: "value1##value2",
    },
});
import pulumi
import pulumi_keycloak as keycloak
realm = keycloak.Realm("realm",
    realm="my-realm",
    enabled=True)
realm_role = keycloak.Role("realm_role",
    realm_id=realm.id,
    name="my-realm-role",
    description="My Realm Role",
    attributes={
        "key": "value",
        "multivalue": "value1##value2",
    })
package main
import (
	"github.com/pulumi/pulumi-keycloak/sdk/v6/go/keycloak"
	"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
		}
		_, err = keycloak.NewRole(ctx, "realm_role", &keycloak.RoleArgs{
			RealmId:     realm.ID(),
			Name:        pulumi.String("my-realm-role"),
			Description: pulumi.String("My Realm Role"),
			Attributes: pulumi.StringMap{
				"key":        pulumi.String("value"),
				"multivalue": pulumi.String("value1##value2"),
			},
		})
		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 realmRole = new Keycloak.Role("realm_role", new()
    {
        RealmId = realm.Id,
        Name = "my-realm-role",
        Description = "My Realm Role",
        Attributes = 
        {
            { "key", "value" },
            { "multivalue", "value1##value2" },
        },
    });
});
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.Role;
import com.pulumi.keycloak.RoleArgs;
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 realmRole = new Role("realmRole", RoleArgs.builder()
            .realmId(realm.id())
            .name("my-realm-role")
            .description("My Realm Role")
            .attributes(Map.ofEntries(
                Map.entry("key", "value"),
                Map.entry("multivalue", "value1##value2")
            ))
            .build());
    }
}
resources:
  realm:
    type: keycloak:Realm
    properties:
      realm: my-realm
      enabled: true
  realmRole:
    type: keycloak:Role
    name: realm_role
    properties:
      realmId: ${realm.id}
      name: my-realm-role
      description: My Realm Role
      attributes:
        key: value
        multivalue: value1##value2
Client Role)
import * as pulumi from "@pulumi/pulumi";
import * as keycloak from "@pulumi/keycloak";
const realm = new keycloak.Realm("realm", {
    realm: "my-realm",
    enabled: true,
});
const openidClient = new keycloak.openid.Client("openid_client", {
    realmId: realm.id,
    clientId: "client",
    name: "client",
    enabled: true,
    accessType: "CONFIDENTIAL",
    validRedirectUris: ["http://localhost:8080/openid-callback"],
});
const clientRole = new keycloak.Role("client_role", {
    realmId: realm.id,
    clientId: openidClientKeycloakClient.id,
    name: "my-client-role",
    description: "My Client Role",
    attributes: {
        key: "value",
    },
});
import pulumi
import pulumi_keycloak as keycloak
realm = keycloak.Realm("realm",
    realm="my-realm",
    enabled=True)
openid_client = keycloak.openid.Client("openid_client",
    realm_id=realm.id,
    client_id="client",
    name="client",
    enabled=True,
    access_type="CONFIDENTIAL",
    valid_redirect_uris=["http://localhost:8080/openid-callback"])
client_role = keycloak.Role("client_role",
    realm_id=realm.id,
    client_id=openid_client_keycloak_client["id"],
    name="my-client-role",
    description="My Client Role",
    attributes={
        "key": "value",
    })
package main
import (
	"github.com/pulumi/pulumi-keycloak/sdk/v6/go/keycloak"
	"github.com/pulumi/pulumi-keycloak/sdk/v6/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
		}
		_, err = openid.NewClient(ctx, "openid_client", &openid.ClientArgs{
			RealmId:    realm.ID(),
			ClientId:   pulumi.String("client"),
			Name:       pulumi.String("client"),
			Enabled:    pulumi.Bool(true),
			AccessType: pulumi.String("CONFIDENTIAL"),
			ValidRedirectUris: pulumi.StringArray{
				pulumi.String("http://localhost:8080/openid-callback"),
			},
		})
		if err != nil {
			return err
		}
		_, err = keycloak.NewRole(ctx, "client_role", &keycloak.RoleArgs{
			RealmId:     realm.ID(),
			ClientId:    pulumi.Any(openidClientKeycloakClient.Id),
			Name:        pulumi.String("my-client-role"),
			Description: pulumi.String("My Client Role"),
			Attributes: pulumi.StringMap{
				"key": pulumi.String("value"),
			},
		})
		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 openidClient = new Keycloak.OpenId.Client("openid_client", new()
    {
        RealmId = realm.Id,
        ClientId = "client",
        Name = "client",
        Enabled = true,
        AccessType = "CONFIDENTIAL",
        ValidRedirectUris = new[]
        {
            "http://localhost:8080/openid-callback",
        },
    });
    var clientRole = new Keycloak.Role("client_role", new()
    {
        RealmId = realm.Id,
        ClientId = openidClientKeycloakClient.Id,
        Name = "my-client-role",
        Description = "My Client Role",
        Attributes = 
        {
            { "key", "value" },
        },
    });
});
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 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 openidClient = new Client("openidClient", ClientArgs.builder()
            .realmId(realm.id())
            .clientId("client")
            .name("client")
            .enabled(true)
            .accessType("CONFIDENTIAL")
            .validRedirectUris("http://localhost:8080/openid-callback")
            .build());
        var clientRole = new Role("clientRole", RoleArgs.builder()
            .realmId(realm.id())
            .clientId(openidClientKeycloakClient.id())
            .name("my-client-role")
            .description("My Client Role")
            .attributes(Map.of("key", "value"))
            .build());
    }
}
resources:
  realm:
    type: keycloak:Realm
    properties:
      realm: my-realm
      enabled: true
  openidClient:
    type: keycloak:openid:Client
    name: openid_client
    properties:
      realmId: ${realm.id}
      clientId: client
      name: client
      enabled: true
      accessType: CONFIDENTIAL
      validRedirectUris:
        - http://localhost:8080/openid-callback
  clientRole:
    type: keycloak:Role
    name: client_role
    properties:
      realmId: ${realm.id}
      clientId: ${openidClientKeycloakClient.id}
      name: my-client-role
      description: My Client Role
      attributes:
        key: value
Composite Role)
import * as pulumi from "@pulumi/pulumi";
import * as keycloak from "@pulumi/keycloak";
const realm = new keycloak.Realm("realm", {
    realm: "my-realm",
    enabled: true,
});
// realm roles
const createRole = new keycloak.Role("create_role", {
    realmId: realm.id,
    name: "create",
    attributes: {
        key: "value",
    },
});
const readRole = new keycloak.Role("read_role", {
    realmId: realm.id,
    name: "read",
    attributes: {
        key: "value",
    },
});
const updateRole = new keycloak.Role("update_role", {
    realmId: realm.id,
    name: "update",
    attributes: {
        key: "value",
    },
});
const deleteRole = new keycloak.Role("delete_role", {
    realmId: realm.id,
    name: "delete",
    attributes: {
        key: "value",
    },
});
// client role
const openidClient = new keycloak.openid.Client("openid_client", {
    realmId: realm.id,
    clientId: "client",
    name: "client",
    enabled: true,
    accessType: "CONFIDENTIAL",
    validRedirectUris: ["http://localhost:8080/openid-callback"],
});
const clientRole = new keycloak.Role("client_role", {
    realmId: realm.id,
    clientId: openidClientKeycloakClient.id,
    name: "my-client-role",
    description: "My Client Role",
    attributes: {
        key: "value",
    },
});
const adminRole = new keycloak.Role("admin_role", {
    realmId: realm.id,
    name: "admin",
    compositeRoles: [
        createRole.id,
        readRole.id,
        updateRole.id,
        deleteRole.id,
        clientRole.id,
    ],
    attributes: {
        key: "value",
    },
});
import pulumi
import pulumi_keycloak as keycloak
realm = keycloak.Realm("realm",
    realm="my-realm",
    enabled=True)
# realm roles
create_role = keycloak.Role("create_role",
    realm_id=realm.id,
    name="create",
    attributes={
        "key": "value",
    })
read_role = keycloak.Role("read_role",
    realm_id=realm.id,
    name="read",
    attributes={
        "key": "value",
    })
update_role = keycloak.Role("update_role",
    realm_id=realm.id,
    name="update",
    attributes={
        "key": "value",
    })
delete_role = keycloak.Role("delete_role",
    realm_id=realm.id,
    name="delete",
    attributes={
        "key": "value",
    })
# client role
openid_client = keycloak.openid.Client("openid_client",
    realm_id=realm.id,
    client_id="client",
    name="client",
    enabled=True,
    access_type="CONFIDENTIAL",
    valid_redirect_uris=["http://localhost:8080/openid-callback"])
client_role = keycloak.Role("client_role",
    realm_id=realm.id,
    client_id=openid_client_keycloak_client["id"],
    name="my-client-role",
    description="My Client Role",
    attributes={
        "key": "value",
    })
admin_role = keycloak.Role("admin_role",
    realm_id=realm.id,
    name="admin",
    composite_roles=[
        create_role.id,
        read_role.id,
        update_role.id,
        delete_role.id,
        client_role.id,
    ],
    attributes={
        "key": "value",
    })
package main
import (
	"github.com/pulumi/pulumi-keycloak/sdk/v6/go/keycloak"
	"github.com/pulumi/pulumi-keycloak/sdk/v6/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
		}
		// realm roles
		createRole, err := keycloak.NewRole(ctx, "create_role", &keycloak.RoleArgs{
			RealmId: realm.ID(),
			Name:    pulumi.String("create"),
			Attributes: pulumi.StringMap{
				"key": pulumi.String("value"),
			},
		})
		if err != nil {
			return err
		}
		readRole, err := keycloak.NewRole(ctx, "read_role", &keycloak.RoleArgs{
			RealmId: realm.ID(),
			Name:    pulumi.String("read"),
			Attributes: pulumi.StringMap{
				"key": pulumi.String("value"),
			},
		})
		if err != nil {
			return err
		}
		updateRole, err := keycloak.NewRole(ctx, "update_role", &keycloak.RoleArgs{
			RealmId: realm.ID(),
			Name:    pulumi.String("update"),
			Attributes: pulumi.StringMap{
				"key": pulumi.String("value"),
			},
		})
		if err != nil {
			return err
		}
		deleteRole, err := keycloak.NewRole(ctx, "delete_role", &keycloak.RoleArgs{
			RealmId: realm.ID(),
			Name:    pulumi.String("delete"),
			Attributes: pulumi.StringMap{
				"key": pulumi.String("value"),
			},
		})
		if err != nil {
			return err
		}
		// client role
		_, err = openid.NewClient(ctx, "openid_client", &openid.ClientArgs{
			RealmId:    realm.ID(),
			ClientId:   pulumi.String("client"),
			Name:       pulumi.String("client"),
			Enabled:    pulumi.Bool(true),
			AccessType: pulumi.String("CONFIDENTIAL"),
			ValidRedirectUris: pulumi.StringArray{
				pulumi.String("http://localhost:8080/openid-callback"),
			},
		})
		if err != nil {
			return err
		}
		clientRole, err := keycloak.NewRole(ctx, "client_role", &keycloak.RoleArgs{
			RealmId:     realm.ID(),
			ClientId:    pulumi.Any(openidClientKeycloakClient.Id),
			Name:        pulumi.String("my-client-role"),
			Description: pulumi.String("My Client Role"),
			Attributes: pulumi.StringMap{
				"key": pulumi.String("value"),
			},
		})
		if err != nil {
			return err
		}
		_, err = keycloak.NewRole(ctx, "admin_role", &keycloak.RoleArgs{
			RealmId: realm.ID(),
			Name:    pulumi.String("admin"),
			CompositeRoles: pulumi.StringArray{
				createRole.ID(),
				readRole.ID(),
				updateRole.ID(),
				deleteRole.ID(),
				clientRole.ID(),
			},
			Attributes: pulumi.StringMap{
				"key": pulumi.String("value"),
			},
		})
		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,
    });
    // realm roles
    var createRole = new Keycloak.Role("create_role", new()
    {
        RealmId = realm.Id,
        Name = "create",
        Attributes = 
        {
            { "key", "value" },
        },
    });
    var readRole = new Keycloak.Role("read_role", new()
    {
        RealmId = realm.Id,
        Name = "read",
        Attributes = 
        {
            { "key", "value" },
        },
    });
    var updateRole = new Keycloak.Role("update_role", new()
    {
        RealmId = realm.Id,
        Name = "update",
        Attributes = 
        {
            { "key", "value" },
        },
    });
    var deleteRole = new Keycloak.Role("delete_role", new()
    {
        RealmId = realm.Id,
        Name = "delete",
        Attributes = 
        {
            { "key", "value" },
        },
    });
    // client role
    var openidClient = new Keycloak.OpenId.Client("openid_client", new()
    {
        RealmId = realm.Id,
        ClientId = "client",
        Name = "client",
        Enabled = true,
        AccessType = "CONFIDENTIAL",
        ValidRedirectUris = new[]
        {
            "http://localhost:8080/openid-callback",
        },
    });
    var clientRole = new Keycloak.Role("client_role", new()
    {
        RealmId = realm.Id,
        ClientId = openidClientKeycloakClient.Id,
        Name = "my-client-role",
        Description = "My Client Role",
        Attributes = 
        {
            { "key", "value" },
        },
    });
    var adminRole = new Keycloak.Role("admin_role", new()
    {
        RealmId = realm.Id,
        Name = "admin",
        CompositeRoles = new[]
        {
            createRole.Id,
            readRole.Id,
            updateRole.Id,
            deleteRole.Id,
            clientRole.Id,
        },
        Attributes = 
        {
            { "key", "value" },
        },
    });
});
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.Role;
import com.pulumi.keycloak.RoleArgs;
import com.pulumi.keycloak.openid.Client;
import com.pulumi.keycloak.openid.ClientArgs;
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());
        // realm roles
        var createRole = new Role("createRole", RoleArgs.builder()
            .realmId(realm.id())
            .name("create")
            .attributes(Map.of("key", "value"))
            .build());
        var readRole = new Role("readRole", RoleArgs.builder()
            .realmId(realm.id())
            .name("read")
            .attributes(Map.of("key", "value"))
            .build());
        var updateRole = new Role("updateRole", RoleArgs.builder()
            .realmId(realm.id())
            .name("update")
            .attributes(Map.of("key", "value"))
            .build());
        var deleteRole = new Role("deleteRole", RoleArgs.builder()
            .realmId(realm.id())
            .name("delete")
            .attributes(Map.of("key", "value"))
            .build());
        // client role
        var openidClient = new Client("openidClient", ClientArgs.builder()
            .realmId(realm.id())
            .clientId("client")
            .name("client")
            .enabled(true)
            .accessType("CONFIDENTIAL")
            .validRedirectUris("http://localhost:8080/openid-callback")
            .build());
        var clientRole = new Role("clientRole", RoleArgs.builder()
            .realmId(realm.id())
            .clientId(openidClientKeycloakClient.id())
            .name("my-client-role")
            .description("My Client Role")
            .attributes(Map.of("key", "value"))
            .build());
        var adminRole = new Role("adminRole", RoleArgs.builder()
            .realmId(realm.id())
            .name("admin")
            .compositeRoles(            
                createRole.id(),
                readRole.id(),
                updateRole.id(),
                deleteRole.id(),
                clientRole.id())
            .attributes(Map.of("key", "value"))
            .build());
    }
}
resources:
  realm:
    type: keycloak:Realm
    properties:
      realm: my-realm
      enabled: true
  # realm roles
  createRole:
    type: keycloak:Role
    name: create_role
    properties:
      realmId: ${realm.id}
      name: create
      attributes:
        key: value
  readRole:
    type: keycloak:Role
    name: read_role
    properties:
      realmId: ${realm.id}
      name: read
      attributes:
        key: value
  updateRole:
    type: keycloak:Role
    name: update_role
    properties:
      realmId: ${realm.id}
      name: update
      attributes:
        key: value
  deleteRole:
    type: keycloak:Role
    name: delete_role
    properties:
      realmId: ${realm.id}
      name: delete
      attributes:
        key: value
  # client role
  openidClient:
    type: keycloak:openid:Client
    name: openid_client
    properties:
      realmId: ${realm.id}
      clientId: client
      name: client
      enabled: true
      accessType: CONFIDENTIAL
      validRedirectUris:
        - http://localhost:8080/openid-callback
  clientRole:
    type: keycloak:Role
    name: client_role
    properties:
      realmId: ${realm.id}
      clientId: ${openidClientKeycloakClient.id}
      name: my-client-role
      description: My Client Role
      attributes:
        key: value
  adminRole:
    type: keycloak:Role
    name: admin_role
    properties:
      realmId: ${realm.id}
      name: admin
      compositeRoles:
        - ${createRole.id}
        - ${readRole.id}
        - ${updateRole.id}
        - ${deleteRole.id}
        - ${clientRole.id}
      attributes:
        key: value
Create Role Resource
Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.
Constructor syntax
new Role(name: string, args: RoleArgs, opts?: CustomResourceOptions);@overload
def Role(resource_name: str,
         args: RoleArgs,
         opts: Optional[ResourceOptions] = None)
@overload
def Role(resource_name: str,
         opts: Optional[ResourceOptions] = None,
         realm_id: Optional[str] = None,
         attributes: Optional[Mapping[str, str]] = None,
         client_id: Optional[str] = None,
         composite_roles: Optional[Sequence[str]] = None,
         description: Optional[str] = None,
         import_: Optional[bool] = None,
         name: Optional[str] = None)func NewRole(ctx *Context, name string, args RoleArgs, opts ...ResourceOption) (*Role, error)public Role(string name, RoleArgs args, CustomResourceOptions? opts = null)type: keycloak:Role
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 RoleArgs
 - 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 RoleArgs
 - 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 RoleArgs
 - The arguments to resource properties.
 - opts ResourceOption
 - Bag of options to control resource's behavior.
 
- name string
 - The unique name of the resource.
 - args RoleArgs
 - The arguments to resource properties.
 - opts CustomResourceOptions
 - Bag of options to control resource's behavior.
 
- name String
 - The unique name of the resource.
 - args RoleArgs
 - The arguments to resource properties.
 - options CustomResourceOptions
 - Bag of options to control resource's behavior.
 
Constructor example
The following reference example uses placeholder values for all input properties.
var roleResource = new Keycloak.Role("roleResource", new()
{
    RealmId = "string",
    Attributes = 
    {
        { "string", "string" },
    },
    ClientId = "string",
    CompositeRoles = new[]
    {
        "string",
    },
    Description = "string",
    Import = false,
    Name = "string",
});
example, err := keycloak.NewRole(ctx, "roleResource", &keycloak.RoleArgs{
	RealmId: pulumi.String("string"),
	Attributes: pulumi.StringMap{
		"string": pulumi.String("string"),
	},
	ClientId: pulumi.String("string"),
	CompositeRoles: pulumi.StringArray{
		pulumi.String("string"),
	},
	Description: pulumi.String("string"),
	Import:      pulumi.Bool(false),
	Name:        pulumi.String("string"),
})
var roleResource = new Role("roleResource", RoleArgs.builder()
    .realmId("string")
    .attributes(Map.of("string", "string"))
    .clientId("string")
    .compositeRoles("string")
    .description("string")
    .import_(false)
    .name("string")
    .build());
role_resource = keycloak.Role("roleResource",
    realm_id="string",
    attributes={
        "string": "string",
    },
    client_id="string",
    composite_roles=["string"],
    description="string",
    import_=False,
    name="string")
const roleResource = new keycloak.Role("roleResource", {
    realmId: "string",
    attributes: {
        string: "string",
    },
    clientId: "string",
    compositeRoles: ["string"],
    description: "string",
    "import": false,
    name: "string",
});
type: keycloak:Role
properties:
    attributes:
        string: string
    clientId: string
    compositeRoles:
        - string
    description: string
    import: false
    name: string
    realmId: string
Role Resource Properties
To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.
Inputs
In Python, inputs that are objects can be passed either as argument classes or as dictionary literals.
The Role resource accepts the following input properties:
- Realm
Id string - The realm this role exists within.
 - Attributes Dictionary<string, string>
 - A map representing attributes for the role. In order to add multivalue attributes, use 
##to seperate the values. Max length for each value is 255 chars - Client
Id string - When specified, this role will be created as a client role attached to the client with the provided ID
 - Composite
Roles List<string> - When specified, this role will be a composite role, composed of all roles that have an ID present within this list.
 - Description string
 - The description of the role
 - Import bool
 - When 
true, the role with the specifiednameis assumed to already exist, and it will be imported into state instead of being created. This attribute is useful when dealing with roles that Keycloak creates automatically during realm creation, such as the client rolescreate-client,view-realm, ... for the clientrealm-managementcreated per realm. Note, that the role will not be removed during destruction ifimportistrue. - Name string
 - The name of the role
 
- Realm
Id string - The realm this role exists within.
 - Attributes map[string]string
 - A map representing attributes for the role. In order to add multivalue attributes, use 
##to seperate the values. Max length for each value is 255 chars - Client
Id string - When specified, this role will be created as a client role attached to the client with the provided ID
 - Composite
Roles []string - When specified, this role will be a composite role, composed of all roles that have an ID present within this list.
 - Description string
 - The description of the role
 - Import bool
 - When 
true, the role with the specifiednameis assumed to already exist, and it will be imported into state instead of being created. This attribute is useful when dealing with roles that Keycloak creates automatically during realm creation, such as the client rolescreate-client,view-realm, ... for the clientrealm-managementcreated per realm. Note, that the role will not be removed during destruction ifimportistrue. - Name string
 - The name of the role
 
- realm
Id String - The realm this role exists within.
 - attributes Map<String,String>
 - A map representing attributes for the role. In order to add multivalue attributes, use 
##to seperate the values. Max length for each value is 255 chars - client
Id String - When specified, this role will be created as a client role attached to the client with the provided ID
 - composite
Roles List<String> - When specified, this role will be a composite role, composed of all roles that have an ID present within this list.
 - description String
 - The description of the role
 - import_ Boolean
 - When 
true, the role with the specifiednameis assumed to already exist, and it will be imported into state instead of being created. This attribute is useful when dealing with roles that Keycloak creates automatically during realm creation, such as the client rolescreate-client,view-realm, ... for the clientrealm-managementcreated per realm. Note, that the role will not be removed during destruction ifimportistrue. - name String
 - The name of the role
 
- realm
Id string - The realm this role exists within.
 - attributes {[key: string]: string}
 - A map representing attributes for the role. In order to add multivalue attributes, use 
##to seperate the values. Max length for each value is 255 chars - client
Id string - When specified, this role will be created as a client role attached to the client with the provided ID
 - composite
Roles string[] - When specified, this role will be a composite role, composed of all roles that have an ID present within this list.
 - description string
 - The description of the role
 - import boolean
 - When 
true, the role with the specifiednameis assumed to already exist, and it will be imported into state instead of being created. This attribute is useful when dealing with roles that Keycloak creates automatically during realm creation, such as the client rolescreate-client,view-realm, ... for the clientrealm-managementcreated per realm. Note, that the role will not be removed during destruction ifimportistrue. - name string
 - The name of the role
 
- realm_
id str - The realm this role exists within.
 - attributes Mapping[str, str]
 - A map representing attributes for the role. In order to add multivalue attributes, use 
##to seperate the values. Max length for each value is 255 chars - client_
id str - When specified, this role will be created as a client role attached to the client with the provided ID
 - composite_
roles Sequence[str] - When specified, this role will be a composite role, composed of all roles that have an ID present within this list.
 - description str
 - The description of the role
 - import_ bool
 - When 
true, the role with the specifiednameis assumed to already exist, and it will be imported into state instead of being created. This attribute is useful when dealing with roles that Keycloak creates automatically during realm creation, such as the client rolescreate-client,view-realm, ... for the clientrealm-managementcreated per realm. Note, that the role will not be removed during destruction ifimportistrue. - name str
 - The name of the role
 
- realm
Id String - The realm this role exists within.
 - attributes Map<String>
 - A map representing attributes for the role. In order to add multivalue attributes, use 
##to seperate the values. Max length for each value is 255 chars - client
Id String - When specified, this role will be created as a client role attached to the client with the provided ID
 - composite
Roles List<String> - When specified, this role will be a composite role, composed of all roles that have an ID present within this list.
 - description String
 - The description of the role
 - import Boolean
 - When 
true, the role with the specifiednameis assumed to already exist, and it will be imported into state instead of being created. This attribute is useful when dealing with roles that Keycloak creates automatically during realm creation, such as the client rolescreate-client,view-realm, ... for the clientrealm-managementcreated per realm. Note, that the role will not be removed during destruction ifimportistrue. - name String
 - The name of the role
 
Outputs
All input properties are implicitly available as output properties. Additionally, the Role 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 Role Resource
Get an existing Role 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?: RoleState, opts?: CustomResourceOptions): Role@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        attributes: Optional[Mapping[str, str]] = None,
        client_id: Optional[str] = None,
        composite_roles: Optional[Sequence[str]] = None,
        description: Optional[str] = None,
        import_: Optional[bool] = None,
        name: Optional[str] = None,
        realm_id: Optional[str] = None) -> Rolefunc GetRole(ctx *Context, name string, id IDInput, state *RoleState, opts ...ResourceOption) (*Role, error)public static Role Get(string name, Input<string> id, RoleState? state, CustomResourceOptions? opts = null)public static Role get(String name, Output<String> id, RoleState state, CustomResourceOptions options)resources:  _:    type: keycloak:Role    get:      id: ${id}- 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.
 
- Attributes Dictionary<string, string>
 - A map representing attributes for the role. In order to add multivalue attributes, use 
##to seperate the values. Max length for each value is 255 chars - Client
Id string - When specified, this role will be created as a client role attached to the client with the provided ID
 - Composite
Roles List<string> - When specified, this role will be a composite role, composed of all roles that have an ID present within this list.
 - Description string
 - The description of the role
 - Import bool
 - When 
true, the role with the specifiednameis assumed to already exist, and it will be imported into state instead of being created. This attribute is useful when dealing with roles that Keycloak creates automatically during realm creation, such as the client rolescreate-client,view-realm, ... for the clientrealm-managementcreated per realm. Note, that the role will not be removed during destruction ifimportistrue. - Name string
 - The name of the role
 - Realm
Id string - The realm this role exists within.
 
- Attributes map[string]string
 - A map representing attributes for the role. In order to add multivalue attributes, use 
##to seperate the values. Max length for each value is 255 chars - Client
Id string - When specified, this role will be created as a client role attached to the client with the provided ID
 - Composite
Roles []string - When specified, this role will be a composite role, composed of all roles that have an ID present within this list.
 - Description string
 - The description of the role
 - Import bool
 - When 
true, the role with the specifiednameis assumed to already exist, and it will be imported into state instead of being created. This attribute is useful when dealing with roles that Keycloak creates automatically during realm creation, such as the client rolescreate-client,view-realm, ... for the clientrealm-managementcreated per realm. Note, that the role will not be removed during destruction ifimportistrue. - Name string
 - The name of the role
 - Realm
Id string - The realm this role exists within.
 
- attributes Map<String,String>
 - A map representing attributes for the role. In order to add multivalue attributes, use 
##to seperate the values. Max length for each value is 255 chars - client
Id String - When specified, this role will be created as a client role attached to the client with the provided ID
 - composite
Roles List<String> - When specified, this role will be a composite role, composed of all roles that have an ID present within this list.
 - description String
 - The description of the role
 - import_ Boolean
 - When 
true, the role with the specifiednameis assumed to already exist, and it will be imported into state instead of being created. This attribute is useful when dealing with roles that Keycloak creates automatically during realm creation, such as the client rolescreate-client,view-realm, ... for the clientrealm-managementcreated per realm. Note, that the role will not be removed during destruction ifimportistrue. - name String
 - The name of the role
 - realm
Id String - The realm this role exists within.
 
- attributes {[key: string]: string}
 - A map representing attributes for the role. In order to add multivalue attributes, use 
##to seperate the values. Max length for each value is 255 chars - client
Id string - When specified, this role will be created as a client role attached to the client with the provided ID
 - composite
Roles string[] - When specified, this role will be a composite role, composed of all roles that have an ID present within this list.
 - description string
 - The description of the role
 - import boolean
 - When 
true, the role with the specifiednameis assumed to already exist, and it will be imported into state instead of being created. This attribute is useful when dealing with roles that Keycloak creates automatically during realm creation, such as the client rolescreate-client,view-realm, ... for the clientrealm-managementcreated per realm. Note, that the role will not be removed during destruction ifimportistrue. - name string
 - The name of the role
 - realm
Id string - The realm this role exists within.
 
- attributes Mapping[str, str]
 - A map representing attributes for the role. In order to add multivalue attributes, use 
##to seperate the values. Max length for each value is 255 chars - client_
id str - When specified, this role will be created as a client role attached to the client with the provided ID
 - composite_
roles Sequence[str] - When specified, this role will be a composite role, composed of all roles that have an ID present within this list.
 - description str
 - The description of the role
 - import_ bool
 - When 
true, the role with the specifiednameis assumed to already exist, and it will be imported into state instead of being created. This attribute is useful when dealing with roles that Keycloak creates automatically during realm creation, such as the client rolescreate-client,view-realm, ... for the clientrealm-managementcreated per realm. Note, that the role will not be removed during destruction ifimportistrue. - name str
 - The name of the role
 - realm_
id str - The realm this role exists within.
 
- attributes Map<String>
 - A map representing attributes for the role. In order to add multivalue attributes, use 
##to seperate the values. Max length for each value is 255 chars - client
Id String - When specified, this role will be created as a client role attached to the client with the provided ID
 - composite
Roles List<String> - When specified, this role will be a composite role, composed of all roles that have an ID present within this list.
 - description String
 - The description of the role
 - import Boolean
 - When 
true, the role with the specifiednameis assumed to already exist, and it will be imported into state instead of being created. This attribute is useful when dealing with roles that Keycloak creates automatically during realm creation, such as the client rolescreate-client,view-realm, ... for the clientrealm-managementcreated per realm. Note, that the role will not be removed during destruction ifimportistrue. - name String
 - The name of the role
 - realm
Id String - The realm this role exists within.
 
Import
Roles can be imported using the format {{realm_id}}/{{role_id}}, where role_id is the unique ID that Keycloak assigns
to the role. The ID is not easy to find in the GUI, but it appears in the URL when editing the role.
Example:
bash
$ pulumi import keycloak:index/role:Role role my-realm/7e8cf32a-8acb-4d34-89c4-04fb1d10ccad
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 
keycloakTerraform Provider.