1. Packages
  2. Keycloak Provider
  3. API Docs
  4. getGroup
Keycloak v5.4.0 published on Monday, Dec 9, 2024 by Pulumi

keycloak.getGroup

Explore with Pulumi AI

keycloak logo
Keycloak v5.4.0 published on Monday, Dec 9, 2024 by Pulumi

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

    Example Usage

    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("group_roles", {
        realmId: realm.id,
        groupId: group.apply(group => group.id),
        roleIds: [offlineAccess.apply(offlineAccess => offlineAccess.id)],
    });
    
    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("group_roles",
        realm_id=realm.id,
        group_id=group.id,
        role_ids=[offline_access.id])
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-keycloak/sdk/v5/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, keycloak.GetRoleOutputArgs{
    			RealmId: realm.ID(),
    			Name:    pulumi.String("offline_access"),
    		}, nil)
    		group := keycloak.LookupGroupOutput(ctx, keycloak.GetGroupOutputArgs{
    			RealmId: realm.ID(),
    			Name:    pulumi.String("group"),
    		}, nil)
    		_, err = keycloak.NewGroupRoles(ctx, "group_roles", &keycloak.GroupRolesArgs{
    			RealmId: realm.ID(),
    			GroupId: pulumi.String(group.ApplyT(func(group keycloak.GetGroupResult) (*string, error) {
    				return &group.Id, nil
    			}).(pulumi.StringPtrOutput)),
    			RoleIds: pulumi.StringArray{
    				pulumi.String(offlineAccess.ApplyT(func(offlineAccess keycloak.GetRoleResult) (*string, error) {
    					return &offlineAccess.Id, nil
    				}).(pulumi.StringPtrOutput)),
    			},
    		})
    		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 offlineAccess = Keycloak.GetRole.Invoke(new()
        {
            RealmId = realm.Id,
            Name = "offline_access",
        });
    
        var @group = Keycloak.GetGroup.Invoke(new()
        {
            RealmId = realm.Id,
            Name = "group",
        });
    
        var groupRoles = new Keycloak.GroupRoles("group_roles", new()
        {
            RealmId = realm.Id,
            GroupId = @group.Apply(@group => @group.Apply(getGroupResult => getGroupResult.Id)),
            RoleIds = new[]
            {
                offlineAccess.Apply(getRoleResult => getRoleResult.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.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());
    
        }
    }
    
    resources:
      realm:
        type: keycloak:Realm
        properties:
          realm: my-realm
          enabled: true
      groupRoles:
        type: keycloak:GroupRoles
        name: group_roles
        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, string>
    Id string
    The provider-assigned unique ID for this managed resource.
    Name string
    ParentId string
    Path string
    RealmId string
    Attributes map[string]string
    Id string
    The provider-assigned unique ID for this managed resource.
    Name string
    ParentId string
    Path string
    RealmId string
    attributes Map<String,String>
    id String
    The provider-assigned unique ID for this managed resource.
    name String
    parentId String
    path String
    realmId String
    attributes {[key: string]: string}
    id string
    The provider-assigned unique ID for this managed resource.
    name string
    parentId string
    path string
    realmId string
    attributes Mapping[str, str]
    id str
    The provider-assigned unique ID for this managed resource.
    name str
    parent_id str
    path str
    realm_id str
    attributes Map<String>
    id String
    The provider-assigned unique ID for this managed resource.
    name String
    parentId String
    path String
    realmId String

    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.4.0 published on Monday, Dec 9, 2024 by Pulumi