Welcome to Pulumi Registry, your window into the cloud. Read the announcement.

Keycloak

v4.7.0 published on Thursday, Nov 18, 2021 by Pulumi

getUserRealmRoles

This data source can be used to fetch the realm roles of a user within Keycloak.

Example Usage

using Pulumi;
using Keycloak = Pulumi.Keycloak;

class MyStack : Stack
{
    public MyStack()
    {
        var masterRealm = Output.Create(Keycloak.GetRealm.InvokeAsync(new Keycloak.GetRealmArgs
        {
            Realm = "master",
        }));
        var defaultAdminUser = masterRealm.Apply(masterRealm => Output.Create(Keycloak.GetUser.InvokeAsync(new Keycloak.GetUserArgs
        {
            RealmId = masterRealm.Id,
            Username = "keycloak",
        })));
        var userRealmRoles = Output.Tuple(masterRealm, defaultAdminUser).Apply(values =>
        {
            var masterRealm = values.Item1;
            var defaultAdminUser = values.Item2;
            return Output.Create(Keycloak.GetUserRealmRoles.InvokeAsync(new Keycloak.GetUserRealmRolesArgs
            {
                RealmId = masterRealm.Id,
                UserId = defaultAdminUser.Id,
            }));
        });
        this.KeycloakUserRoleNames = userRealmRoles.Apply(userRealmRoles => userRealmRoles.RoleNames);
    }

    [Output("keycloakUserRoleNames")]
    public Output<string> KeycloakUserRoleNames { get; set; }
}
package main

import (
	"github.com/pulumi/pulumi-keycloak/sdk/v4/go/keycloak"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		masterRealm, err := keycloak.LookupRealm(ctx, &GetRealmArgs{
			Realm: "master",
		}, nil)
		if err != nil {
			return err
		}
		defaultAdminUser, err := keycloak.LookupUser(ctx, &GetUserArgs{
			RealmId:  masterRealm.Id,
			Username: "keycloak",
		}, nil)
		if err != nil {
			return err
		}
		userRealmRoles, err := keycloak.GetUserRealmRoles(ctx, &GetUserRealmRolesArgs{
			RealmId: masterRealm.Id,
			UserId:  defaultAdminUser.Id,
		}, nil)
		if err != nil {
			return err
		}
		ctx.Export("keycloakUserRoleNames", userRealmRoles.RoleNames)
		return nil
	})
}
import pulumi
import pulumi_keycloak as keycloak

master_realm = keycloak.get_realm(realm="master")
default_admin_user = keycloak.get_user(realm_id=master_realm.id,
    username="keycloak")
user_realm_roles = keycloak.get_user_realm_roles(realm_id=master_realm.id,
    user_id=default_admin_user.id)
pulumi.export("keycloakUserRoleNames", user_realm_roles.role_names)
import * as pulumi from "@pulumi/pulumi";
import * as keycloak from "@pulumi/keycloak";

const masterRealm = keycloak.getRealm({
    realm: "master",
});
const defaultAdminUser = masterRealm.then(masterRealm => keycloak.getUser({
    realmId: masterRealm.id,
    username: "keycloak",
}));
const userRealmRoles = Promise.all([masterRealm, defaultAdminUser]).then(([masterRealm, defaultAdminUser]) => keycloak.getUserRealmRoles({
    realmId: masterRealm.id,
    userId: defaultAdminUser.id,
}));
export const keycloakUserRoleNames = userRealmRoles.then(userRealmRoles => userRealmRoles.roleNames);

Using getUserRealmRoles

Two invocation forms are available. The direct form accepts plain arguments and either blocks until the result value is available, or returns a Promise-wrapped result. The output form accepts Input-wrapped arguments and returns an Output-wrapped result.

function getUserRealmRoles(args: GetUserRealmRolesArgs, opts?: InvokeOptions): Promise<GetUserRealmRolesResult>
function getUserRealmRolesOutput(args: GetUserRealmRolesOutputArgs, opts?: InvokeOptions): Output<GetUserRealmRolesResult>
def get_user_realm_roles(realm_id: Optional[str] = None,
                         user_id: Optional[str] = None,
                         opts: Optional[InvokeOptions] = None) -> GetUserRealmRolesResult
def get_user_realm_roles_output(realm_id: Optional[pulumi.Input[str]] = None,
                         user_id: Optional[pulumi.Input[str]] = None,
                         opts: Optional[InvokeOptions] = None) -> Output[GetUserRealmRolesResult]
func GetUserRealmRoles(ctx *Context, args *GetUserRealmRolesArgs, opts ...InvokeOption) (*GetUserRealmRolesResult, error)
func GetUserRealmRolesOutput(ctx *Context, args *GetUserRealmRolesOutputArgs, opts ...InvokeOption) GetUserRealmRolesResultOutput

> Note: This function is named GetUserRealmRoles in the Go SDK.

public static class GetUserRealmRoles 
{
    public static Task<GetUserRealmRolesResult> InvokeAsync(GetUserRealmRolesArgs args, InvokeOptions? opts = null)
    public static Output<GetUserRealmRolesResult> Invoke(GetUserRealmRolesInvokeArgs args, InvokeOptions? opts = null)
}

The following arguments are supported:

RealmId string
The realm this user belongs to.
UserId string
The ID of the user to query realm roles for.
RealmId string
The realm this user belongs to.
UserId string
The ID of the user to query realm roles for.
realmId string
The realm this user belongs to.
userId string
The ID of the user to query realm roles for.
realm_id str
The realm this user belongs to.
user_id str
The ID of the user to query realm roles for.

getUserRealmRoles Result

The following output properties are available:

Id string
The provider-assigned unique ID for this managed resource.
RealmId string
RoleNames List<string>
(Computed) A list of realm roles that belong to this user.
UserId string
Id string
The provider-assigned unique ID for this managed resource.
RealmId string
RoleNames []string
(Computed) A list of realm roles that belong to this user.
UserId string
id string
The provider-assigned unique ID for this managed resource.
realmId string
roleNames string[]
(Computed) A list of realm roles that belong to this user.
userId string
id str
The provider-assigned unique ID for this managed resource.
realm_id str
role_names Sequence[str]
(Computed) A list of realm roles that belong to this user.
user_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.