Keycloak

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

ClientServiceAccountRole

Allows for assigning client roles to the service account of an openid client. You need to set service_accounts_enabled to true for the openid client that should be assigned the role.

If you’d like to attach realm roles to a service account, please use the keycloak.openid.ClientServiceAccountRealmRole resource.

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,
        });
        // client1 provides a role to other clients
        var client1 = new Keycloak.OpenId.Client("client1", new Keycloak.OpenId.ClientArgs
        {
            RealmId = realm.Id,
        });
        var client1Role = new Keycloak.Role("client1Role", new Keycloak.RoleArgs
        {
            RealmId = realm.Id,
            ClientId = client1.Id,
            Description = "A role that client1 provides",
        });
        // client2 is assigned the role of client1
        var client2 = new Keycloak.OpenId.Client("client2", new Keycloak.OpenId.ClientArgs
        {
            RealmId = realm.Id,
            ServiceAccountsEnabled = true,
        });
        var client2ServiceAccountRole = new Keycloak.OpenId.ClientServiceAccountRole("client2ServiceAccountRole", new Keycloak.OpenId.ClientServiceAccountRoleArgs
        {
            RealmId = realm.Id,
            ServiceAccountUserId = client2.ServiceAccountUserId,
            ClientId = client1.Id,
            Role = client1Role.Name,
        });
    }

}
package main

import (
	"github.com/pulumi/pulumi-keycloak/sdk/v4/go/keycloak"
	"github.com/pulumi/pulumi-keycloak/sdk/v4/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
		}
		client1, err := openid.NewClient(ctx, "client1", &openid.ClientArgs{
			RealmId: realm.ID(),
		})
		if err != nil {
			return err
		}
		client1Role, err := keycloak.NewRole(ctx, "client1Role", &keycloak.RoleArgs{
			RealmId:     realm.ID(),
			ClientId:    client1.ID(),
			Description: pulumi.String("A role that client1 provides"),
		})
		if err != nil {
			return err
		}
		client2, err := openid.NewClient(ctx, "client2", &openid.ClientArgs{
			RealmId:                realm.ID(),
			ServiceAccountsEnabled: pulumi.Bool(true),
		})
		if err != nil {
			return err
		}
		_, err = openid.NewClientServiceAccountRole(ctx, "client2ServiceAccountRole", &openid.ClientServiceAccountRoleArgs{
			RealmId:              realm.ID(),
			ServiceAccountUserId: client2.ServiceAccountUserId,
			ClientId:             client1.ID(),
			Role:                 client1Role.Name,
		})
		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.openid.Client;
import com.pulumi.keycloak.openid.ClientArgs;
import com.pulumi.keycloak.Role;
import com.pulumi.keycloak.RoleArgs;
import com.pulumi.keycloak.openid.ClientServiceAccountRole;
import com.pulumi.keycloak.openid.ClientServiceAccountRoleArgs;
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 client1 = new Client("client1", ClientArgs.builder()        
            .realmId(realm.id())
            .build());

        var client1Role = new Role("client1Role", RoleArgs.builder()        
            .realmId(realm.id())
            .clientId(client1.id())
            .description("A role that client1 provides")
            .build());

        var client2 = new Client("client2", ClientArgs.builder()        
            .realmId(realm.id())
            .serviceAccountsEnabled(true)
            .build());

        var client2ServiceAccountRole = new ClientServiceAccountRole("client2ServiceAccountRole", ClientServiceAccountRoleArgs.builder()        
            .realmId(realm.id())
            .serviceAccountUserId(client2.serviceAccountUserId())
            .clientId(client1.id())
            .role(client1Role.name())
            .build());

    }
}
import pulumi
import pulumi_keycloak as keycloak

realm = keycloak.Realm("realm",
    realm="my-realm",
    enabled=True)
# client1 provides a role to other clients
client1 = keycloak.openid.Client("client1", realm_id=realm.id)
client1_role = keycloak.Role("client1Role",
    realm_id=realm.id,
    client_id=client1.id,
    description="A role that client1 provides")
# client2 is assigned the role of client1
client2 = keycloak.openid.Client("client2",
    realm_id=realm.id,
    service_accounts_enabled=True)
client2_service_account_role = keycloak.openid.ClientServiceAccountRole("client2ServiceAccountRole",
    realm_id=realm.id,
    service_account_user_id=client2.service_account_user_id,
    client_id=client1.id,
    role=client1_role.name)
import * as pulumi from "@pulumi/pulumi";
import * as keycloak from "@pulumi/keycloak";

const realm = new keycloak.Realm("realm", {
    realm: "my-realm",
    enabled: true,
});
// client1 provides a role to other clients
const client1 = new keycloak.openid.Client("client1", {realmId: realm.id});
const client1Role = new keycloak.Role("client1Role", {
    realmId: realm.id,
    clientId: client1.id,
    description: "A role that client1 provides",
});
// client2 is assigned the role of client1
const client2 = new keycloak.openid.Client("client2", {
    realmId: realm.id,
    serviceAccountsEnabled: true,
});
const client2ServiceAccountRole = new keycloak.openid.ClientServiceAccountRole("client2ServiceAccountRole", {
    realmId: realm.id,
    serviceAccountUserId: client2.serviceAccountUserId,
    clientId: client1.id,
    role: client1Role.name,
});
resources:
  realm:
    type: keycloak:Realm
    properties:
      realm: my-realm
      enabled: true
  # client1 provides a role to other clients
  client1:
    type: keycloak:openid:Client
    properties:
      realmId: ${realm.id}
  client1Role:
    type: keycloak:Role
    properties:
      realmId: ${realm.id}
      clientId: ${client1.id}
      description: A role that client1 provides
  # client2 is assigned the role of client1
  client2:
    type: keycloak:openid:Client
    properties:
      realmId: ${realm.id}
      serviceAccountsEnabled: true
  client2ServiceAccountRole:
    type: keycloak:openid:ClientServiceAccountRole
    properties:
      realmId: ${realm.id}
      serviceAccountUserId: ${client2.serviceAccountUserId}
      clientId: ${client1.id}
      role: ${client1Role.name}

Create a ClientServiceAccountRole Resource

new ClientServiceAccountRole(name: string, args: ClientServiceAccountRoleArgs, opts?: CustomResourceOptions);
@overload
def ClientServiceAccountRole(resource_name: str,
                             opts: Optional[ResourceOptions] = None,
                             client_id: Optional[str] = None,
                             realm_id: Optional[str] = None,
                             role: Optional[str] = None,
                             service_account_user_id: Optional[str] = None)
@overload
def ClientServiceAccountRole(resource_name: str,
                             args: ClientServiceAccountRoleArgs,
                             opts: Optional[ResourceOptions] = None)
func NewClientServiceAccountRole(ctx *Context, name string, args ClientServiceAccountRoleArgs, opts ...ResourceOption) (*ClientServiceAccountRole, error)
public ClientServiceAccountRole(string name, ClientServiceAccountRoleArgs args, CustomResourceOptions? opts = null)
public ClientServiceAccountRole(String name, ClientServiceAccountRoleArgs args)
public ClientServiceAccountRole(String name, ClientServiceAccountRoleArgs args, CustomResourceOptions options)
type: keycloak:openid:ClientServiceAccountRole
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.

name string
The unique name of the resource.
args ClientServiceAccountRoleArgs
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 ClientServiceAccountRoleArgs
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 ClientServiceAccountRoleArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name string
The unique name of the resource.
args ClientServiceAccountRoleArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
name String
The unique name of the resource.
args ClientServiceAccountRoleArgs
The arguments to resource properties.
options CustomResourceOptions
Bag of options to control resource's behavior.

ClientServiceAccountRole Resource Properties

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

Inputs

The ClientServiceAccountRole resource accepts the following input properties:

ClientId string

The id of the client that provides the role.

RealmId string

The realm the clients and roles belong to.

Role string

The name of the role that is assigned.

ServiceAccountUserId string

The id of the service account that is assigned the role (the service account of the client that "consumes" the role).

ClientId string

The id of the client that provides the role.

RealmId string

The realm the clients and roles belong to.

Role string

The name of the role that is assigned.

ServiceAccountUserId string

The id of the service account that is assigned the role (the service account of the client that "consumes" the role).

clientId String

The id of the client that provides the role.

realmId String

The realm the clients and roles belong to.

role String

The name of the role that is assigned.

serviceAccountUserId String

The id of the service account that is assigned the role (the service account of the client that "consumes" the role).

clientId string

The id of the client that provides the role.

realmId string

The realm the clients and roles belong to.

role string

The name of the role that is assigned.

serviceAccountUserId string

The id of the service account that is assigned the role (the service account of the client that "consumes" the role).

client_id str

The id of the client that provides the role.

realm_id str

The realm the clients and roles belong to.

role str

The name of the role that is assigned.

service_account_user_id str

The id of the service account that is assigned the role (the service account of the client that "consumes" the role).

clientId String

The id of the client that provides the role.

realmId String

The realm the clients and roles belong to.

role String

The name of the role that is assigned.

serviceAccountUserId String

The id of the service account that is assigned the role (the service account of the client that "consumes" the role).

Outputs

All input properties are implicitly available as output properties. Additionally, the ClientServiceAccountRole 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 an Existing ClientServiceAccountRole Resource

Get an existing ClientServiceAccountRole 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?: ClientServiceAccountRoleState, opts?: CustomResourceOptions): ClientServiceAccountRole
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        client_id: Optional[str] = None,
        realm_id: Optional[str] = None,
        role: Optional[str] = None,
        service_account_user_id: Optional[str] = None) -> ClientServiceAccountRole
func GetClientServiceAccountRole(ctx *Context, name string, id IDInput, state *ClientServiceAccountRoleState, opts ...ResourceOption) (*ClientServiceAccountRole, error)
public static ClientServiceAccountRole Get(string name, Input<string> id, ClientServiceAccountRoleState? state, CustomResourceOptions? opts = null)
public static ClientServiceAccountRole get(String name, Output<String> id, ClientServiceAccountRoleState state, CustomResourceOptions options)
Resource lookup is not supported in YAML
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.
The following state arguments are supported:
ClientId string

The id of the client that provides the role.

RealmId string

The realm the clients and roles belong to.

Role string

The name of the role that is assigned.

ServiceAccountUserId string

The id of the service account that is assigned the role (the service account of the client that "consumes" the role).

ClientId string

The id of the client that provides the role.

RealmId string

The realm the clients and roles belong to.

Role string

The name of the role that is assigned.

ServiceAccountUserId string

The id of the service account that is assigned the role (the service account of the client that "consumes" the role).

clientId String

The id of the client that provides the role.

realmId String

The realm the clients and roles belong to.

role String

The name of the role that is assigned.

serviceAccountUserId String

The id of the service account that is assigned the role (the service account of the client that "consumes" the role).

clientId string

The id of the client that provides the role.

realmId string

The realm the clients and roles belong to.

role string

The name of the role that is assigned.

serviceAccountUserId string

The id of the service account that is assigned the role (the service account of the client that "consumes" the role).

client_id str

The id of the client that provides the role.

realm_id str

The realm the clients and roles belong to.

role str

The name of the role that is assigned.

service_account_user_id str

The id of the service account that is assigned the role (the service account of the client that "consumes" the role).

clientId String

The id of the client that provides the role.

realmId String

The realm the clients and roles belong to.

role String

The name of the role that is assigned.

serviceAccountUserId String

The id of the service account that is assigned the role (the service account of the client that "consumes" the role).

Import

This resource can be imported using the format {{realmId}}/{{serviceAccountUserId}}/{{clientId}}/{{roleId}}. Examplebash

 $ pulumi import keycloak:openid/clientServiceAccountRole:ClientServiceAccountRole client2_service_account_role my-realm/489ba513-1ceb-49ba-ae0b-1ab1f5099ebf/baf01820-0f8b-4494-9be2-fb3bc8a397a4/c7230ab7-8e4e-4135-995d-e81b50696ad8

Package Details

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

This Pulumi package is based on the keycloak Terraform Provider.