keycloak.User
Explore with Pulumi AI
Allows for creating and managing Users within Keycloak.
This resource was created primarily to enable the acceptance tests for the keycloak.Group
resource. Creating users within
Keycloak is not recommended. Instead, users should be federated from external sources by configuring user federation providers
or identity providers.
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 user = new keycloak.User("user", {
realmId: realm.id,
username: "bob",
enabled: true,
email: "bob@domain.com",
firstName: "Bob",
lastName: "Bobson",
});
const userWithInitialPassword = new keycloak.User("user_with_initial_password", {
realmId: realm.id,
username: "alice",
enabled: true,
email: "alice@domain.com",
firstName: "Alice",
lastName: "Aliceberg",
attributes: {
foo: "bar",
multivalue: "value1##value2",
},
initialPassword: {
value: "some password",
temporary: true,
},
});
import pulumi
import pulumi_keycloak as keycloak
realm = keycloak.Realm("realm",
realm="my-realm",
enabled=True)
user = keycloak.User("user",
realm_id=realm.id,
username="bob",
enabled=True,
email="bob@domain.com",
first_name="Bob",
last_name="Bobson")
user_with_initial_password = keycloak.User("user_with_initial_password",
realm_id=realm.id,
username="alice",
enabled=True,
email="alice@domain.com",
first_name="Alice",
last_name="Aliceberg",
attributes={
"foo": "bar",
"multivalue": "value1##value2",
},
initial_password={
"value": "some password",
"temporary": True,
})
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
}
_, err = keycloak.NewUser(ctx, "user", &keycloak.UserArgs{
RealmId: realm.ID(),
Username: pulumi.String("bob"),
Enabled: pulumi.Bool(true),
Email: pulumi.String("bob@domain.com"),
FirstName: pulumi.String("Bob"),
LastName: pulumi.String("Bobson"),
})
if err != nil {
return err
}
_, err = keycloak.NewUser(ctx, "user_with_initial_password", &keycloak.UserArgs{
RealmId: realm.ID(),
Username: pulumi.String("alice"),
Enabled: pulumi.Bool(true),
Email: pulumi.String("alice@domain.com"),
FirstName: pulumi.String("Alice"),
LastName: pulumi.String("Aliceberg"),
Attributes: pulumi.StringMap{
"foo": pulumi.String("bar"),
"multivalue": pulumi.String("value1##value2"),
},
InitialPassword: &keycloak.UserInitialPasswordArgs{
Value: pulumi.String("some password"),
Temporary: pulumi.Bool(true),
},
})
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 user = new Keycloak.User("user", new()
{
RealmId = realm.Id,
Username = "bob",
Enabled = true,
Email = "bob@domain.com",
FirstName = "Bob",
LastName = "Bobson",
});
var userWithInitialPassword = new Keycloak.User("user_with_initial_password", new()
{
RealmId = realm.Id,
Username = "alice",
Enabled = true,
Email = "alice@domain.com",
FirstName = "Alice",
LastName = "Aliceberg",
Attributes =
{
{ "foo", "bar" },
{ "multivalue", "value1##value2" },
},
InitialPassword = new Keycloak.Inputs.UserInitialPasswordArgs
{
Value = "some password",
Temporary = true,
},
});
});
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.User;
import com.pulumi.keycloak.UserArgs;
import com.pulumi.keycloak.inputs.UserInitialPasswordArgs;
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 user = new User("user", UserArgs.builder()
.realmId(realm.id())
.username("bob")
.enabled(true)
.email("bob@domain.com")
.firstName("Bob")
.lastName("Bobson")
.build());
var userWithInitialPassword = new User("userWithInitialPassword", UserArgs.builder()
.realmId(realm.id())
.username("alice")
.enabled(true)
.email("alice@domain.com")
.firstName("Alice")
.lastName("Aliceberg")
.attributes(Map.ofEntries(
Map.entry("foo", "bar"),
Map.entry("multivalue", "value1##value2")
))
.initialPassword(UserInitialPasswordArgs.builder()
.value("some password")
.temporary(true)
.build())
.build());
}
}
resources:
realm:
type: keycloak:Realm
properties:
realm: my-realm
enabled: true
user:
type: keycloak:User
properties:
realmId: ${realm.id}
username: bob
enabled: true
email: bob@domain.com
firstName: Bob
lastName: Bobson
userWithInitialPassword:
type: keycloak:User
name: user_with_initial_password
properties:
realmId: ${realm.id}
username: alice
enabled: true
email: alice@domain.com
firstName: Alice
lastName: Aliceberg
attributes:
foo: bar
multivalue: value1##value2
initialPassword:
value: some password
temporary: true
Create User Resource
Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.
Constructor syntax
new User(name: string, args: UserArgs, opts?: CustomResourceOptions);
@overload
def User(resource_name: str,
args: UserArgs,
opts: Optional[ResourceOptions] = None)
@overload
def User(resource_name: str,
opts: Optional[ResourceOptions] = None,
realm_id: Optional[str] = None,
username: Optional[str] = None,
attributes: Optional[Mapping[str, str]] = None,
email: Optional[str] = None,
email_verified: Optional[bool] = None,
enabled: Optional[bool] = None,
federated_identities: Optional[Sequence[UserFederatedIdentityArgs]] = None,
first_name: Optional[str] = None,
initial_password: Optional[UserInitialPasswordArgs] = None,
last_name: Optional[str] = None,
required_actions: Optional[Sequence[str]] = None)
func NewUser(ctx *Context, name string, args UserArgs, opts ...ResourceOption) (*User, error)
public User(string name, UserArgs args, CustomResourceOptions? opts = null)
type: keycloak:User
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.
Parameters
- name string
- The unique name of the resource.
- args UserArgs
- 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 UserArgs
- 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 UserArgs
- The arguments to resource properties.
- opts ResourceOption
- Bag of options to control resource's behavior.
- name string
- The unique name of the resource.
- args UserArgs
- The arguments to resource properties.
- opts CustomResourceOptions
- Bag of options to control resource's behavior.
- name String
- The unique name of the resource.
- args UserArgs
- 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 userResource = new Keycloak.User("userResource", new()
{
RealmId = "string",
Username = "string",
Attributes =
{
{ "string", "string" },
},
Email = "string",
EmailVerified = false,
Enabled = false,
FederatedIdentities = new[]
{
new Keycloak.Inputs.UserFederatedIdentityArgs
{
IdentityProvider = "string",
UserId = "string",
UserName = "string",
},
},
FirstName = "string",
InitialPassword = new Keycloak.Inputs.UserInitialPasswordArgs
{
Value = "string",
Temporary = false,
},
LastName = "string",
RequiredActions = new[]
{
"string",
},
});
example, err := keycloak.NewUser(ctx, "userResource", &keycloak.UserArgs{
RealmId: pulumi.String("string"),
Username: pulumi.String("string"),
Attributes: pulumi.StringMap{
"string": pulumi.String("string"),
},
Email: pulumi.String("string"),
EmailVerified: pulumi.Bool(false),
Enabled: pulumi.Bool(false),
FederatedIdentities: keycloak.UserFederatedIdentityArray{
&keycloak.UserFederatedIdentityArgs{
IdentityProvider: pulumi.String("string"),
UserId: pulumi.String("string"),
UserName: pulumi.String("string"),
},
},
FirstName: pulumi.String("string"),
InitialPassword: &keycloak.UserInitialPasswordArgs{
Value: pulumi.String("string"),
Temporary: pulumi.Bool(false),
},
LastName: pulumi.String("string"),
RequiredActions: pulumi.StringArray{
pulumi.String("string"),
},
})
var userResource = new User("userResource", UserArgs.builder()
.realmId("string")
.username("string")
.attributes(Map.of("string", "string"))
.email("string")
.emailVerified(false)
.enabled(false)
.federatedIdentities(UserFederatedIdentityArgs.builder()
.identityProvider("string")
.userId("string")
.userName("string")
.build())
.firstName("string")
.initialPassword(UserInitialPasswordArgs.builder()
.value("string")
.temporary(false)
.build())
.lastName("string")
.requiredActions("string")
.build());
user_resource = keycloak.User("userResource",
realm_id="string",
username="string",
attributes={
"string": "string",
},
email="string",
email_verified=False,
enabled=False,
federated_identities=[{
"identity_provider": "string",
"user_id": "string",
"user_name": "string",
}],
first_name="string",
initial_password={
"value": "string",
"temporary": False,
},
last_name="string",
required_actions=["string"])
const userResource = new keycloak.User("userResource", {
realmId: "string",
username: "string",
attributes: {
string: "string",
},
email: "string",
emailVerified: false,
enabled: false,
federatedIdentities: [{
identityProvider: "string",
userId: "string",
userName: "string",
}],
firstName: "string",
initialPassword: {
value: "string",
temporary: false,
},
lastName: "string",
requiredActions: ["string"],
});
type: keycloak:User
properties:
attributes:
string: string
email: string
emailVerified: false
enabled: false
federatedIdentities:
- identityProvider: string
userId: string
userName: string
firstName: string
initialPassword:
temporary: false
value: string
lastName: string
realmId: string
requiredActions:
- string
username: string
User 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 User resource accepts the following input properties:
- Realm
Id string - The realm this user belongs to.
- Username string
- The unique username of this user.
- Attributes Dictionary<string, string>
- A map representing attributes for the user. In order to add multivalue attributes, use
##
to seperate the values. Max length for each value is 255 chars - Email string
- The user's email.
- Email
Verified bool - Whether the email address was validated or not. Default to
false
. - Enabled bool
- When false, this user cannot log in. Defaults to
true
. - Federated
Identities List<UserFederated Identity> - When specified, the user will be linked to a federated identity provider. Refer to the federated user example for more details.
- First
Name string - The user's first name.
- Initial
Password UserInitial Password - When given, the user's initial password will be set. This attribute is only respected during initial user creation.
- Last
Name string - The user's last name.
- Required
Actions List<string> - A list of required user actions.
- Realm
Id string - The realm this user belongs to.
- Username string
- The unique username of this user.
- Attributes map[string]string
- A map representing attributes for the user. In order to add multivalue attributes, use
##
to seperate the values. Max length for each value is 255 chars - Email string
- The user's email.
- Email
Verified bool - Whether the email address was validated or not. Default to
false
. - Enabled bool
- When false, this user cannot log in. Defaults to
true
. - Federated
Identities []UserFederated Identity Args - When specified, the user will be linked to a federated identity provider. Refer to the federated user example for more details.
- First
Name string - The user's first name.
- Initial
Password UserInitial Password Args - When given, the user's initial password will be set. This attribute is only respected during initial user creation.
- Last
Name string - The user's last name.
- Required
Actions []string - A list of required user actions.
- realm
Id String - The realm this user belongs to.
- username String
- The unique username of this user.
- attributes Map<String,String>
- A map representing attributes for the user. In order to add multivalue attributes, use
##
to seperate the values. Max length for each value is 255 chars - email String
- The user's email.
- email
Verified Boolean - Whether the email address was validated or not. Default to
false
. - enabled Boolean
- When false, this user cannot log in. Defaults to
true
. - federated
Identities List<UserFederated Identity> - When specified, the user will be linked to a federated identity provider. Refer to the federated user example for more details.
- first
Name String - The user's first name.
- initial
Password UserInitial Password - When given, the user's initial password will be set. This attribute is only respected during initial user creation.
- last
Name String - The user's last name.
- required
Actions List<String> - A list of required user actions.
- realm
Id string - The realm this user belongs to.
- username string
- The unique username of this user.
- attributes {[key: string]: string}
- A map representing attributes for the user. In order to add multivalue attributes, use
##
to seperate the values. Max length for each value is 255 chars - email string
- The user's email.
- email
Verified boolean - Whether the email address was validated or not. Default to
false
. - enabled boolean
- When false, this user cannot log in. Defaults to
true
. - federated
Identities UserFederated Identity[] - When specified, the user will be linked to a federated identity provider. Refer to the federated user example for more details.
- first
Name string - The user's first name.
- initial
Password UserInitial Password - When given, the user's initial password will be set. This attribute is only respected during initial user creation.
- last
Name string - The user's last name.
- required
Actions string[] - A list of required user actions.
- realm_
id str - The realm this user belongs to.
- username str
- The unique username of this user.
- attributes Mapping[str, str]
- A map representing attributes for the user. In order to add multivalue attributes, use
##
to seperate the values. Max length for each value is 255 chars - email str
- The user's email.
- email_
verified bool - Whether the email address was validated or not. Default to
false
. - enabled bool
- When false, this user cannot log in. Defaults to
true
. - federated_
identities Sequence[UserFederated Identity Args] - When specified, the user will be linked to a federated identity provider. Refer to the federated user example for more details.
- first_
name str - The user's first name.
- initial_
password UserInitial Password Args - When given, the user's initial password will be set. This attribute is only respected during initial user creation.
- last_
name str - The user's last name.
- required_
actions Sequence[str] - A list of required user actions.
- realm
Id String - The realm this user belongs to.
- username String
- The unique username of this user.
- attributes Map<String>
- A map representing attributes for the user. In order to add multivalue attributes, use
##
to seperate the values. Max length for each value is 255 chars - email String
- The user's email.
- email
Verified Boolean - Whether the email address was validated or not. Default to
false
. - enabled Boolean
- When false, this user cannot log in. Defaults to
true
. - federated
Identities List<Property Map> - When specified, the user will be linked to a federated identity provider. Refer to the federated user example for more details.
- first
Name String - The user's first name.
- initial
Password Property Map - When given, the user's initial password will be set. This attribute is only respected during initial user creation.
- last
Name String - The user's last name.
- required
Actions List<String> - A list of required user actions.
Outputs
All input properties are implicitly available as output properties. Additionally, the User 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 User Resource
Get an existing User 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?: UserState, opts?: CustomResourceOptions): User
@staticmethod
def get(resource_name: str,
id: str,
opts: Optional[ResourceOptions] = None,
attributes: Optional[Mapping[str, str]] = None,
email: Optional[str] = None,
email_verified: Optional[bool] = None,
enabled: Optional[bool] = None,
federated_identities: Optional[Sequence[UserFederatedIdentityArgs]] = None,
first_name: Optional[str] = None,
initial_password: Optional[UserInitialPasswordArgs] = None,
last_name: Optional[str] = None,
realm_id: Optional[str] = None,
required_actions: Optional[Sequence[str]] = None,
username: Optional[str] = None) -> User
func GetUser(ctx *Context, name string, id IDInput, state *UserState, opts ...ResourceOption) (*User, error)
public static User Get(string name, Input<string> id, UserState? state, CustomResourceOptions? opts = null)
public static User get(String name, Output<String> id, UserState 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.
- Attributes Dictionary<string, string>
- A map representing attributes for the user. In order to add multivalue attributes, use
##
to seperate the values. Max length for each value is 255 chars - Email string
- The user's email.
- Email
Verified bool - Whether the email address was validated or not. Default to
false
. - Enabled bool
- When false, this user cannot log in. Defaults to
true
. - Federated
Identities List<UserFederated Identity> - When specified, the user will be linked to a federated identity provider. Refer to the federated user example for more details.
- First
Name string - The user's first name.
- Initial
Password UserInitial Password - When given, the user's initial password will be set. This attribute is only respected during initial user creation.
- Last
Name string - The user's last name.
- Realm
Id string - The realm this user belongs to.
- Required
Actions List<string> - A list of required user actions.
- Username string
- The unique username of this user.
- Attributes map[string]string
- A map representing attributes for the user. In order to add multivalue attributes, use
##
to seperate the values. Max length for each value is 255 chars - Email string
- The user's email.
- Email
Verified bool - Whether the email address was validated or not. Default to
false
. - Enabled bool
- When false, this user cannot log in. Defaults to
true
. - Federated
Identities []UserFederated Identity Args - When specified, the user will be linked to a federated identity provider. Refer to the federated user example for more details.
- First
Name string - The user's first name.
- Initial
Password UserInitial Password Args - When given, the user's initial password will be set. This attribute is only respected during initial user creation.
- Last
Name string - The user's last name.
- Realm
Id string - The realm this user belongs to.
- Required
Actions []string - A list of required user actions.
- Username string
- The unique username of this user.
- attributes Map<String,String>
- A map representing attributes for the user. In order to add multivalue attributes, use
##
to seperate the values. Max length for each value is 255 chars - email String
- The user's email.
- email
Verified Boolean - Whether the email address was validated or not. Default to
false
. - enabled Boolean
- When false, this user cannot log in. Defaults to
true
. - federated
Identities List<UserFederated Identity> - When specified, the user will be linked to a federated identity provider. Refer to the federated user example for more details.
- first
Name String - The user's first name.
- initial
Password UserInitial Password - When given, the user's initial password will be set. This attribute is only respected during initial user creation.
- last
Name String - The user's last name.
- realm
Id String - The realm this user belongs to.
- required
Actions List<String> - A list of required user actions.
- username String
- The unique username of this user.
- attributes {[key: string]: string}
- A map representing attributes for the user. In order to add multivalue attributes, use
##
to seperate the values. Max length for each value is 255 chars - email string
- The user's email.
- email
Verified boolean - Whether the email address was validated or not. Default to
false
. - enabled boolean
- When false, this user cannot log in. Defaults to
true
. - federated
Identities UserFederated Identity[] - When specified, the user will be linked to a federated identity provider. Refer to the federated user example for more details.
- first
Name string - The user's first name.
- initial
Password UserInitial Password - When given, the user's initial password will be set. This attribute is only respected during initial user creation.
- last
Name string - The user's last name.
- realm
Id string - The realm this user belongs to.
- required
Actions string[] - A list of required user actions.
- username string
- The unique username of this user.
- attributes Mapping[str, str]
- A map representing attributes for the user. In order to add multivalue attributes, use
##
to seperate the values. Max length for each value is 255 chars - email str
- The user's email.
- email_
verified bool - Whether the email address was validated or not. Default to
false
. - enabled bool
- When false, this user cannot log in. Defaults to
true
. - federated_
identities Sequence[UserFederated Identity Args] - When specified, the user will be linked to a federated identity provider. Refer to the federated user example for more details.
- first_
name str - The user's first name.
- initial_
password UserInitial Password Args - When given, the user's initial password will be set. This attribute is only respected during initial user creation.
- last_
name str - The user's last name.
- realm_
id str - The realm this user belongs to.
- required_
actions Sequence[str] - A list of required user actions.
- username str
- The unique username of this user.
- attributes Map<String>
- A map representing attributes for the user. In order to add multivalue attributes, use
##
to seperate the values. Max length for each value is 255 chars - email String
- The user's email.
- email
Verified Boolean - Whether the email address was validated or not. Default to
false
. - enabled Boolean
- When false, this user cannot log in. Defaults to
true
. - federated
Identities List<Property Map> - When specified, the user will be linked to a federated identity provider. Refer to the federated user example for more details.
- first
Name String - The user's first name.
- initial
Password Property Map - When given, the user's initial password will be set. This attribute is only respected during initial user creation.
- last
Name String - The user's last name.
- realm
Id String - The realm this user belongs to.
- required
Actions List<String> - A list of required user actions.
- username String
- The unique username of this user.
Supporting Types
UserFederatedIdentity, UserFederatedIdentityArgs
- Identity
Provider string - The name of the identity provider
- User
Id string - The ID of the user defined in the identity provider
- User
Name string - The user name of the user defined in the identity provider
- Identity
Provider string - The name of the identity provider
- User
Id string - The ID of the user defined in the identity provider
- User
Name string - The user name of the user defined in the identity provider
- identity
Provider String - The name of the identity provider
- user
Id String - The ID of the user defined in the identity provider
- user
Name String - The user name of the user defined in the identity provider
- identity
Provider string - The name of the identity provider
- user
Id string - The ID of the user defined in the identity provider
- user
Name string - The user name of the user defined in the identity provider
- identity_
provider str - The name of the identity provider
- user_
id str - The ID of the user defined in the identity provider
- user_
name str - The user name of the user defined in the identity provider
- identity
Provider String - The name of the identity provider
- user
Id String - The ID of the user defined in the identity provider
- user
Name String - The user name of the user defined in the identity provider
UserInitialPassword, UserInitialPasswordArgs
Import
Users can be imported using the format {{realm_id}}/{{user_id}}
, where user_id
is the unique ID that Keycloak
assigns to the user upon creation. This value can be found in the GUI when editing the user.
Example:
bash
$ pulumi import keycloak:index/user:User user my-realm/60c3f971-b1d3-4b3a-9035-d16d7540a5e4
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.