Role

# keycloak..Role

Allows for creating and managing roles within Keycloak.

Roles allow you 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", {
    enabled: true,
    realm: "my-realm",
});
const realmRole = new keycloak.Role("realm_role", {
    description: "My Realm Role",
    realmId: realm.id,
});
import pulumi
import pulumi_keycloak as keycloak

realm = keycloak.Realm("realm",
    enabled=True,
    realm="my-realm")
realm_role = keycloak.Role("realmRole",
    description="My Realm Role",
    realm_id=realm.id)
using Pulumi;
using Keycloak = Pulumi.Keycloak;

class MyStack : Stack
{
    public MyStack()
    {
        var realm = new Keycloak.Realm("realm", new Keycloak.RealmArgs
        {
            Enabled = true,
            Realm = "my-realm",
        });
        var realmRole = new Keycloak.Role("realmRole", new Keycloak.RoleArgs
        {
            Description = "My Realm Role",
            RealmId = realm.Id,
        });
    }

}

Example Usage (Client role)

import * as pulumi from "@pulumi/pulumi";
import * as keycloak from "@pulumi/keycloak";

const realm = new keycloak.Realm("realm", {
    enabled: true,
    realm: "my-realm",
});
const client = new keycloak.openid.Client("client", {
    accessType: "BEARER-ONLY",
    clientId: "client",
    enabled: true,
    realmId: realm.id,
});
const clientRole = new keycloak.Role("client_role", {
    clientId: keycloak_client_client.id,
    description: "My Client Role",
    realmId: realm.id,
});
import pulumi
import pulumi_keycloak as keycloak

realm = keycloak.Realm("realm",
    enabled=True,
    realm="my-realm")
client = keycloak.openid.Client("client",
    access_type="BEARER-ONLY",
    client_id="client",
    enabled=True,
    realm_id=realm.id)
client_role = keycloak.Role("clientRole",
    client_id=keycloak_client["client"]["id"],
    description="My Client Role",
    realm_id=realm.id)
using Pulumi;
using Keycloak = Pulumi.Keycloak;

class MyStack : Stack
{
    public MyStack()
    {
        var realm = new Keycloak.Realm("realm", new Keycloak.RealmArgs
        {
            Enabled = true,
            Realm = "my-realm",
        });
        var client = new Keycloak.OpenId.Client("client", new Keycloak.OpenId.ClientArgs
        {
            AccessType = "BEARER-ONLY",
            ClientId = "client",
            Enabled = true,
            RealmId = realm.Id,
        });
        var clientRole = new Keycloak.Role("clientRole", new Keycloak.RoleArgs
        {
            ClientId = keycloak_client.Client.Id,
            Description = "My Client Role",
            RealmId = realm.Id,
        });
    }

}

Example Usage (Composite role)

import * as pulumi from "@pulumi/pulumi";
import * as keycloak from "@pulumi/keycloak";

const realm = new keycloak.Realm("realm", {
    enabled: true,
    realm: "my-realm",
});
const createRole = new keycloak.Role("create_role", {
    realmId: realm.id,
});
const readRole = new keycloak.Role("read_role", {
    realmId: realm.id,
});
const updateRole = new keycloak.Role("update_role", {
    realmId: realm.id,
});
const deleteRole = new keycloak.Role("delete_role", {
    realmId: realm.id,
});
const client = new keycloak.openid.Client("client", {
    accessType: "BEARER-ONLY",
    clientId: "client",
    enabled: true,
    realmId: realm.id,
});
const clientRole = new keycloak.Role("client_role", {
    clientId: keycloak_client_client.id,
    description: "My Client Role",
    realmId: realm.id,
});
const adminRole = new keycloak.Role("admin_role", {
    compositeRoles: [
        "{keycloak_role.create_role.id}",
        "{keycloak_role.read_role.id}",
        "{keycloak_role.update_role.id}",
        "{keycloak_role.delete_role.id}",
        "{keycloak_role.client_role.id}",
    ],
    realmId: realm.id,
});
import pulumi
import pulumi_keycloak as keycloak

realm = keycloak.Realm("realm",
    enabled=True,
    realm="my-realm")
create_role = keycloak.Role("createRole", realm_id=realm.id)
read_role = keycloak.Role("readRole", realm_id=realm.id)
update_role = keycloak.Role("updateRole", realm_id=realm.id)
delete_role = keycloak.Role("deleteRole", realm_id=realm.id)
client = keycloak.openid.Client("client",
    access_type="BEARER-ONLY",
    client_id="client",
    enabled=True,
    realm_id=realm.id)
client_role = keycloak.Role("clientRole",
    client_id=keycloak_client["client"]["id"],
    description="My Client Role",
    realm_id=realm.id)
admin_role = keycloak.Role("adminRole",
    composite_roles=[
        "{keycloak_role.create_role.id}",
        "{keycloak_role.read_role.id}",
        "{keycloak_role.update_role.id}",
        "{keycloak_role.delete_role.id}",
        "{keycloak_role.client_role.id}",
    ],
    realm_id=realm.id)
using Pulumi;
using Keycloak = Pulumi.Keycloak;

class MyStack : Stack
{
    public MyStack()
    {
        var realm = new Keycloak.Realm("realm", new Keycloak.RealmArgs
        {
            Enabled = true,
            Realm = "my-realm",
        });
        var createRole = new Keycloak.Role("createRole", new Keycloak.RoleArgs
        {
            RealmId = realm.Id,
        });
        var readRole = new Keycloak.Role("readRole", new Keycloak.RoleArgs
        {
            RealmId = realm.Id,
        });
        var updateRole = new Keycloak.Role("updateRole", new Keycloak.RoleArgs
        {
            RealmId = realm.Id,
        });
        var deleteRole = new Keycloak.Role("deleteRole", new Keycloak.RoleArgs
        {
            RealmId = realm.Id,
        });
        var client = new Keycloak.OpenId.Client("client", new Keycloak.OpenId.ClientArgs
        {
            AccessType = "BEARER-ONLY",
            ClientId = "client",
            Enabled = true,
            RealmId = realm.Id,
        });
        var clientRole = new Keycloak.Role("clientRole", new Keycloak.RoleArgs
        {
            ClientId = keycloak_client.Client.Id,
            Description = "My Client Role",
            RealmId = realm.Id,
        });
        var adminRole = new Keycloak.Role("adminRole", new Keycloak.RoleArgs
        {
            CompositeRoles = 
            {
                "{keycloak_role.create_role.id}",
                "{keycloak_role.read_role.id}",
                "{keycloak_role.update_role.id}",
                "{keycloak_role.delete_role.id}",
                "{keycloak_role.client_role.id}",
            },
            RealmId = realm.Id,
        });
    }

}

Argument Reference

The following arguments are supported:

  • realm_id - (Required) The realm this role exists within.
  • client_id - (Optional) When specified, this role will be created as a client role attached to the client with the provided ID
  • name - (Required) The name of the role
  • description - (Optional) The description of the role
  • composite_roles - (Optional) When specified, this role will be a composite role, composed of all roles that have an ID present within this list.

Create a Role Resource

new Role(name: string, args: RoleArgs, opts?: CustomResourceOptions);
def Role(resource_name, opts=None, client_id=None, composite_roles=None, description=None, name=None, realm_id=None, __props__=None);
func NewRole(ctx *Context, name string, args RoleArgs, opts ...ResourceOption) (*Role, error)
public Role(string name, RoleArgs args, CustomResourceOptions? opts = null)
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.
opts ResourceOptions
A bag of options that control this 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.

Role Resource Properties

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

Inputs

The Role resource accepts the following input properties:

RealmId string
ClientId string
CompositeRoles List<string>
Description string
Name string
RealmId string
ClientId string
CompositeRoles []string
Description string
Name string
realmId string
clientId string
compositeRoles string[]
description string
name string
realm_id str
client_id str
composite_roles List[str]
description str
name str

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 str
The provider-assigned unique ID for this managed resource.

Look up an 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
static get(resource_name, id, opts=None, client_id=None, composite_roles=None, description=None, name=None, realm_id=None, __props__=None);
func 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)
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.

The following state arguments are supported:

ClientId string
CompositeRoles List<string>
Description string
Name string
RealmId string
ClientId string
CompositeRoles []string
Description string
Name string
RealmId string
clientId string
compositeRoles string[]
description string
name string
realmId string
client_id str
composite_roles List[str]
description str
name str
realm_id str

Package Details

Repository
https://github.com/pulumi/pulumi-keycloak
License
Apache-2.0
Notes
This Pulumi package is based on the keycloak Terraform Provider.