Keycloak

v4.11.0 published on Thursday, Aug 4, 2022 by Pulumi

getGroup

This data source can be used to fetch properties of a Keycloak group for usage with other resources, such as keycloak.GroupRoles.

Example Usage

using Pulumi;
using Keycloak = Pulumi.Keycloak;

class MyStack : Stack
{
    public MyStack()
    {
        var realm = new Keycloak.Realm("realm", new Keycloak.RealmArgs
        {
            RealmName = "my-realm",
            Enabled = true,
        });
        var offlineAccess = Keycloak.GetRole.Invoke(new Keycloak.GetRoleInvokeArgs
        {
            RealmId = realm.Id,
            Name = "offline_access",
        });
        var @group = Keycloak.GetGroup.Invoke(new Keycloak.GetGroupInvokeArgs
        {
            RealmId = realm.Id,
            Name = "group",
        });
        var groupRoles = new Keycloak.GroupRoles("groupRoles", new Keycloak.GroupRolesArgs
        {
            RealmId = realm.Id,
            GroupId = @group.Apply(@group => @group.Id),
            RoleIds = 
            {
                offlineAccess.Apply(offlineAccess => offlineAccess.Id),
            },
        });
    }

}
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 {
		realm, err := keycloak.NewRealm(ctx, "realm", &keycloak.RealmArgs{
			Realm:   pulumi.String("my-realm"),
			Enabled: pulumi.Bool(true),
		})
		if err != nil {
			return err
		}
		offlineAccess := keycloak.LookupRoleOutput(ctx, GetRoleOutputArgs{
			RealmId: realm.ID(),
			Name:    pulumi.String("offline_access"),
		}, nil)
		group := keycloak.LookupGroupOutput(ctx, GetGroupOutputArgs{
			RealmId: realm.ID(),
			Name:    pulumi.String("group"),
		}, nil)
		_, err = keycloak.NewGroupRoles(ctx, "groupRoles", &keycloak.GroupRolesArgs{
			RealmId: realm.ID(),
			GroupId: group.ApplyT(func(group GetGroupResult) (string, error) {
				return group.Id, nil
			}).(pulumi.StringOutput),
			RoleIds: pulumi.StringArray{
				offlineAccess.ApplyT(func(offlineAccess GetRoleResult) (string, error) {
					return offlineAccess.Id, nil
				}).(pulumi.StringOutput),
			},
		})
		if err != nil {
			return err
		}
		return nil
	})
}
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.KeycloakFunctions;
import com.pulumi.keycloak.inputs.GetRoleArgs;
import com.pulumi.keycloak.inputs.GetGroupArgs;
import com.pulumi.keycloak.GroupRoles;
import com.pulumi.keycloak.GroupRolesArgs;
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());

        final var offlineAccess = KeycloakFunctions.getRole(GetRoleArgs.builder()
            .realmId(realm.id())
            .name("offline_access")
            .build());

        final var group = KeycloakFunctions.getGroup(GetGroupArgs.builder()
            .realmId(realm.id())
            .name("group")
            .build());

        var groupRoles = new GroupRoles("groupRoles", GroupRolesArgs.builder()        
            .realmId(realm.id())
            .groupId(group.applyValue(getGroupResult -> getGroupResult).applyValue(group -> group.applyValue(getGroupResult -> getGroupResult.id())))
            .roleIds(offlineAccess.applyValue(getRoleResult -> getRoleResult).applyValue(offlineAccess -> offlineAccess.applyValue(getRoleResult -> getRoleResult.id())))
            .build());

    }
}
import pulumi
import pulumi_keycloak as keycloak

realm = keycloak.Realm("realm",
    realm="my-realm",
    enabled=True)
offline_access = keycloak.get_role_output(realm_id=realm.id,
    name="offline_access")
group = keycloak.get_group_output(realm_id=realm.id,
    name="group")
group_roles = keycloak.GroupRoles("groupRoles",
    realm_id=realm.id,
    group_id=group.id,
    role_ids=[offline_access.id])
import * as pulumi from "@pulumi/pulumi";
import * as keycloak from "@pulumi/keycloak";

const realm = new keycloak.Realm("realm", {
    realm: "my-realm",
    enabled: true,
});
const offlineAccess = keycloak.getRoleOutput({
    realmId: realm.id,
    name: "offline_access",
});
const group = keycloak.getGroupOutput({
    realmId: realm.id,
    name: "group",
});
const groupRoles = new keycloak.GroupRoles("groupRoles", {
    realmId: realm.id,
    groupId: group.apply(group => group.id),
    roleIds: [offlineAccess.apply(offlineAccess => offlineAccess.id)],
});
resources:
  realm:
    type: keycloak:Realm
    properties:
      realm: my-realm
      enabled: true
  groupRoles:
    type: keycloak:GroupRoles
    properties:
      realmId: ${realm.id}
      groupId: ${group.id}
      roleIds:
        - ${offlineAccess.id}
variables:
  offlineAccess:
    Fn::Invoke:
      Function: keycloak:getRole
      Arguments:
        realmId: ${realm.id}
        name: offline_access
  group:
    Fn::Invoke:
      Function: keycloak:getGroup
      Arguments:
        realmId: ${realm.id}
        name: group

Using getGroup

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 getGroup(args: GetGroupArgs, opts?: InvokeOptions): Promise<GetGroupResult>
function getGroupOutput(args: GetGroupOutputArgs, opts?: InvokeOptions): Output<GetGroupResult>
def get_group(name: Optional[str] = None,
              realm_id: Optional[str] = None,
              opts: Optional[InvokeOptions] = None) -> GetGroupResult
def get_group_output(name: Optional[pulumi.Input[str]] = None,
              realm_id: Optional[pulumi.Input[str]] = None,
              opts: Optional[InvokeOptions] = None) -> Output[GetGroupResult]
func LookupGroup(ctx *Context, args *LookupGroupArgs, opts ...InvokeOption) (*LookupGroupResult, error)
func LookupGroupOutput(ctx *Context, args *LookupGroupOutputArgs, opts ...InvokeOption) LookupGroupResultOutput

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

public static class GetGroup 
{
    public static Task<GetGroupResult> InvokeAsync(GetGroupArgs args, InvokeOptions? opts = null)
    public static Output<GetGroupResult> Invoke(GetGroupInvokeArgs args, InvokeOptions? opts = null)
}
public static CompletableFuture<GetGroupResult> getGroup(GetGroupArgs args, InvokeOptions options)
// Output-based functions aren't available in Java yet
Fn::Invoke:
  Function: keycloak:index/getGroup:getGroup
  Arguments:
    # Arguments dictionary

The following arguments are supported:

Name string

The name of the group. If there are multiple groups match name, the first result will be returned.

RealmId string

The realm this group exists within.

Name string

The name of the group. If there are multiple groups match name, the first result will be returned.

RealmId string

The realm this group exists within.

name String

The name of the group. If there are multiple groups match name, the first result will be returned.

realmId String

The realm this group exists within.

name string

The name of the group. If there are multiple groups match name, the first result will be returned.

realmId string

The realm this group exists within.

name str

The name of the group. If there are multiple groups match name, the first result will be returned.

realm_id str

The realm this group exists within.

name String

The name of the group. If there are multiple groups match name, the first result will be returned.

realmId String

The realm this group exists within.

getGroup Result

The following output properties are available:

Attributes Dictionary<string, object>
Id string

The provider-assigned unique ID for this managed resource.

Name string
ParentId string
Path string
RealmId string
Attributes map[string]interface{}
Id string

The provider-assigned unique ID for this managed resource.

Name string
ParentId string
Path string
RealmId string
attributes Map<String,Object>
id String

The provider-assigned unique ID for this managed resource.

name String
parentId String
path String
realmId String
attributes {[key: string]: any}
id string

The provider-assigned unique ID for this managed resource.

name string
parentId string
path string
realmId string
attributes Mapping[str, Any]
id str

The provider-assigned unique ID for this managed resource.

name str
parent_id str
path str
realm_id str
attributes Map<Any>
id String

The provider-assigned unique ID for this managed resource.

name String
parentId String
path String
realmId String

Package Details

Repository
https://github.com/pulumi/pulumi-keycloak
License
Apache-2.0
Notes

This Pulumi package is based on the keycloak Terraform Provider.