1. Packages
  2. Keycloak Provider
  3. API Docs
  4. RealmOptionalClientScopes
Keycloak v6.4.0 published on Wednesday, Apr 16, 2025 by Pulumi

keycloak.RealmOptionalClientScopes

Explore with Pulumi AI

Allows you to manage the set of optional client scopes for a Keycloak realm, which are used when new clients are created.

Note that this resource attempts to be an authoritative source over the optional client scopes for a Keycloak realm, so any Keycloak defaults and manual adjustments will be overwritten.

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 clientScope = new keycloak.openid.ClientScope("client_scope", {
    realmId: realm.id,
    name: "test-client-scope",
});
const optionalScopes = new keycloak.RealmOptionalClientScopes("optional_scopes", {
    realmId: realm.id,
    optionalScopes: [
        "address",
        "phone",
        "offline_access",
        "microprofile-jwt",
        clientScope.name,
    ],
});
Copy
import pulumi
import pulumi_keycloak as keycloak

realm = keycloak.Realm("realm",
    realm="my-realm",
    enabled=True)
client_scope = keycloak.openid.ClientScope("client_scope",
    realm_id=realm.id,
    name="test-client-scope")
optional_scopes = keycloak.RealmOptionalClientScopes("optional_scopes",
    realm_id=realm.id,
    optional_scopes=[
        "address",
        "phone",
        "offline_access",
        "microprofile-jwt",
        client_scope.name,
    ])
Copy
package main

import (
	"github.com/pulumi/pulumi-keycloak/sdk/v6/go/keycloak"
	"github.com/pulumi/pulumi-keycloak/sdk/v6/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
		}
		clientScope, err := openid.NewClientScope(ctx, "client_scope", &openid.ClientScopeArgs{
			RealmId: realm.ID(),
			Name:    pulumi.String("test-client-scope"),
		})
		if err != nil {
			return err
		}
		_, err = keycloak.NewRealmOptionalClientScopes(ctx, "optional_scopes", &keycloak.RealmOptionalClientScopesArgs{
			RealmId: realm.ID(),
			OptionalScopes: pulumi.StringArray{
				pulumi.String("address"),
				pulumi.String("phone"),
				pulumi.String("offline_access"),
				pulumi.String("microprofile-jwt"),
				clientScope.Name,
			},
		})
		if err != nil {
			return err
		}
		return nil
	})
}
Copy
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 clientScope = new Keycloak.OpenId.ClientScope("client_scope", new()
    {
        RealmId = realm.Id,
        Name = "test-client-scope",
    });

    var optionalScopes = new Keycloak.RealmOptionalClientScopes("optional_scopes", new()
    {
        RealmId = realm.Id,
        OptionalScopes = new[]
        {
            "address",
            "phone",
            "offline_access",
            "microprofile-jwt",
            clientScope.Name,
        },
    });

});
Copy
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.ClientScope;
import com.pulumi.keycloak.openid.ClientScopeArgs;
import com.pulumi.keycloak.RealmOptionalClientScopes;
import com.pulumi.keycloak.RealmOptionalClientScopesArgs;
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 clientScope = new ClientScope("clientScope", ClientScopeArgs.builder()
            .realmId(realm.id())
            .name("test-client-scope")
            .build());

        var optionalScopes = new RealmOptionalClientScopes("optionalScopes", RealmOptionalClientScopesArgs.builder()
            .realmId(realm.id())
            .optionalScopes(            
                "address",
                "phone",
                "offline_access",
                "microprofile-jwt",
                clientScope.name())
            .build());

    }
}
Copy
resources:
  realm:
    type: keycloak:Realm
    properties:
      realm: my-realm
      enabled: true
  clientScope:
    type: keycloak:openid:ClientScope
    name: client_scope
    properties:
      realmId: ${realm.id}
      name: test-client-scope
  optionalScopes:
    type: keycloak:RealmOptionalClientScopes
    name: optional_scopes
    properties:
      realmId: ${realm.id}
      optionalScopes:
        - address
        - phone
        - offline_access
        - microprofile-jwt
        - ${clientScope.name}
Copy

Create RealmOptionalClientScopes Resource

Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.

Constructor syntax

new RealmOptionalClientScopes(name: string, args: RealmOptionalClientScopesArgs, opts?: CustomResourceOptions);
@overload
def RealmOptionalClientScopes(resource_name: str,
                              args: RealmOptionalClientScopesArgs,
                              opts: Optional[ResourceOptions] = None)

@overload
def RealmOptionalClientScopes(resource_name: str,
                              opts: Optional[ResourceOptions] = None,
                              optional_scopes: Optional[Sequence[str]] = None,
                              realm_id: Optional[str] = None)
func NewRealmOptionalClientScopes(ctx *Context, name string, args RealmOptionalClientScopesArgs, opts ...ResourceOption) (*RealmOptionalClientScopes, error)
public RealmOptionalClientScopes(string name, RealmOptionalClientScopesArgs args, CustomResourceOptions? opts = null)
public RealmOptionalClientScopes(String name, RealmOptionalClientScopesArgs args)
public RealmOptionalClientScopes(String name, RealmOptionalClientScopesArgs args, CustomResourceOptions options)
type: keycloak:RealmOptionalClientScopes
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.

Parameters

name This property is required. string
The unique name of the resource.
args This property is required. RealmOptionalClientScopesArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
resource_name This property is required. str
The unique name of the resource.
args This property is required. RealmOptionalClientScopesArgs
The arguments to resource properties.
opts ResourceOptions
Bag of options to control resource's behavior.
ctx Context
Context object for the current deployment.
name This property is required. string
The unique name of the resource.
args This property is required. RealmOptionalClientScopesArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name This property is required. string
The unique name of the resource.
args This property is required. RealmOptionalClientScopesArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
name This property is required. String
The unique name of the resource.
args This property is required. RealmOptionalClientScopesArgs
The arguments to resource properties.
options CustomResourceOptions
Bag of options to control resource's behavior.

Constructor example

The following reference example uses placeholder values for all input properties.

var realmOptionalClientScopesResource = new Keycloak.RealmOptionalClientScopes("realmOptionalClientScopesResource", new()
{
    OptionalScopes = new[]
    {
        "string",
    },
    RealmId = "string",
});
Copy
example, err := keycloak.NewRealmOptionalClientScopes(ctx, "realmOptionalClientScopesResource", &keycloak.RealmOptionalClientScopesArgs{
	OptionalScopes: pulumi.StringArray{
		pulumi.String("string"),
	},
	RealmId: pulumi.String("string"),
})
Copy
var realmOptionalClientScopesResource = new RealmOptionalClientScopes("realmOptionalClientScopesResource", RealmOptionalClientScopesArgs.builder()
    .optionalScopes("string")
    .realmId("string")
    .build());
Copy
realm_optional_client_scopes_resource = keycloak.RealmOptionalClientScopes("realmOptionalClientScopesResource",
    optional_scopes=["string"],
    realm_id="string")
Copy
const realmOptionalClientScopesResource = new keycloak.RealmOptionalClientScopes("realmOptionalClientScopesResource", {
    optionalScopes: ["string"],
    realmId: "string",
});
Copy
type: keycloak:RealmOptionalClientScopes
properties:
    optionalScopes:
        - string
    realmId: string
Copy

RealmOptionalClientScopes Resource Properties

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

Inputs

In Python, inputs that are objects can be passed either as argument classes or as dictionary literals.

The RealmOptionalClientScopes resource accepts the following input properties:

OptionalScopes This property is required. List<string>
An array of optional client scope names that should be used when creating new Keycloak clients.
RealmId
This property is required.
Changes to this property will trigger replacement.
string
The realm this client and scopes exists in.
OptionalScopes This property is required. []string
An array of optional client scope names that should be used when creating new Keycloak clients.
RealmId
This property is required.
Changes to this property will trigger replacement.
string
The realm this client and scopes exists in.
optionalScopes This property is required. List<String>
An array of optional client scope names that should be used when creating new Keycloak clients.
realmId
This property is required.
Changes to this property will trigger replacement.
String
The realm this client and scopes exists in.
optionalScopes This property is required. string[]
An array of optional client scope names that should be used when creating new Keycloak clients.
realmId
This property is required.
Changes to this property will trigger replacement.
string
The realm this client and scopes exists in.
optional_scopes This property is required. Sequence[str]
An array of optional client scope names that should be used when creating new Keycloak clients.
realm_id
This property is required.
Changes to this property will trigger replacement.
str
The realm this client and scopes exists in.
optionalScopes This property is required. List<String>
An array of optional client scope names that should be used when creating new Keycloak clients.
realmId
This property is required.
Changes to this property will trigger replacement.
String
The realm this client and scopes exists in.

Outputs

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

Get an existing RealmOptionalClientScopes 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?: RealmOptionalClientScopesState, opts?: CustomResourceOptions): RealmOptionalClientScopes
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        optional_scopes: Optional[Sequence[str]] = None,
        realm_id: Optional[str] = None) -> RealmOptionalClientScopes
func GetRealmOptionalClientScopes(ctx *Context, name string, id IDInput, state *RealmOptionalClientScopesState, opts ...ResourceOption) (*RealmOptionalClientScopes, error)
public static RealmOptionalClientScopes Get(string name, Input<string> id, RealmOptionalClientScopesState? state, CustomResourceOptions? opts = null)
public static RealmOptionalClientScopes get(String name, Output<String> id, RealmOptionalClientScopesState state, CustomResourceOptions options)
resources:  _:    type: keycloak:RealmOptionalClientScopes    get:      id: ${id}
name This property is required.
The unique name of the resulting resource.
id This property is required.
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 This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
name This property is required.
The unique name of the resulting resource.
id This property is required.
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 This property is required.
The unique name of the resulting resource.
id This property is required.
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 This property is required.
The unique name of the resulting resource.
id This property is required.
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:
OptionalScopes List<string>
An array of optional client scope names that should be used when creating new Keycloak clients.
RealmId Changes to this property will trigger replacement. string
The realm this client and scopes exists in.
OptionalScopes []string
An array of optional client scope names that should be used when creating new Keycloak clients.
RealmId Changes to this property will trigger replacement. string
The realm this client and scopes exists in.
optionalScopes List<String>
An array of optional client scope names that should be used when creating new Keycloak clients.
realmId Changes to this property will trigger replacement. String
The realm this client and scopes exists in.
optionalScopes string[]
An array of optional client scope names that should be used when creating new Keycloak clients.
realmId Changes to this property will trigger replacement. string
The realm this client and scopes exists in.
optional_scopes Sequence[str]
An array of optional client scope names that should be used when creating new Keycloak clients.
realm_id Changes to this property will trigger replacement. str
The realm this client and scopes exists in.
optionalScopes List<String>
An array of optional client scope names that should be used when creating new Keycloak clients.
realmId Changes to this property will trigger replacement. String
The realm this client and scopes exists in.

Import

This resource does not support import. Instead of importing, feel free to create this resource

as if it did not already exist on the server.

To learn more about importing existing cloud resources, see Importing resources.

Package Details

Repository
Keycloak pulumi/pulumi-keycloak
License
Apache-2.0
Notes
This Pulumi package is based on the keycloak Terraform Provider.