1. Packages
  2. Keycloak
  3. API Docs
  4. User
Keycloak v5.3.1 published on Monday, Mar 11, 2024 by Pulumi

keycloak.User

Explore with Pulumi AI

keycloak logo
Keycloak v5.3.1 published on Monday, Mar 11, 2024 by Pulumi

    # keycloak.User

    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", {
        enabled: true,
        realm: "my-realm",
    });
    const user = new keycloak.User("user", {
        email: "bob@domain.com",
        enabled: true,
        firstName: "Bob",
        lastName: "Bobson",
        realmId: realm.id,
        username: "bob",
    });
    const userWithInitialPassword = new keycloak.User("userWithInitialPassword", {
        email: "alice@domain.com",
        enabled: true,
        firstName: "Alice",
        initialPassword: {
            temporary: true,
            value: "some password",
        },
        lastName: "Aliceberg",
        realmId: realm.id,
        username: "alice",
    });
    
    import pulumi
    import pulumi_keycloak as keycloak
    
    realm = keycloak.Realm("realm",
        enabled=True,
        realm="my-realm")
    user = keycloak.User("user",
        email="bob@domain.com",
        enabled=True,
        first_name="Bob",
        last_name="Bobson",
        realm_id=realm.id,
        username="bob")
    user_with_initial_password = keycloak.User("userWithInitialPassword",
        email="alice@domain.com",
        enabled=True,
        first_name="Alice",
        initial_password=keycloak.UserInitialPasswordArgs(
            temporary=True,
            value="some password",
        ),
        last_name="Aliceberg",
        realm_id=realm.id,
        username="alice")
    
    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{
    			Enabled: pulumi.Bool(true),
    			Realm:   pulumi.String("my-realm"),
    		})
    		if err != nil {
    			return err
    		}
    		_, err = keycloak.NewUser(ctx, "user", &keycloak.UserArgs{
    			Email:     pulumi.String("bob@domain.com"),
    			Enabled:   pulumi.Bool(true),
    			FirstName: pulumi.String("Bob"),
    			LastName:  pulumi.String("Bobson"),
    			RealmId:   realm.ID(),
    			Username:  pulumi.String("bob"),
    		})
    		if err != nil {
    			return err
    		}
    		_, err = keycloak.NewUser(ctx, "userWithInitialPassword", &keycloak.UserArgs{
    			Email:     pulumi.String("alice@domain.com"),
    			Enabled:   pulumi.Bool(true),
    			FirstName: pulumi.String("Alice"),
    			InitialPassword: &keycloak.UserInitialPasswordArgs{
    				Temporary: pulumi.Bool(true),
    				Value:     pulumi.String("some password"),
    			},
    			LastName: pulumi.String("Aliceberg"),
    			RealmId:  realm.ID(),
    			Username: pulumi.String("alice"),
    		})
    		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()
        {
            Enabled = true,
            RealmName = "my-realm",
        });
    
        var user = new Keycloak.User("user", new()
        {
            Email = "bob@domain.com",
            Enabled = true,
            FirstName = "Bob",
            LastName = "Bobson",
            RealmId = realm.Id,
            Username = "bob",
        });
    
        var userWithInitialPassword = new Keycloak.User("userWithInitialPassword", new()
        {
            Email = "alice@domain.com",
            Enabled = true,
            FirstName = "Alice",
            InitialPassword = new Keycloak.Inputs.UserInitialPasswordArgs
            {
                Temporary = true,
                Value = "some password",
            },
            LastName = "Aliceberg",
            RealmId = realm.Id,
            Username = "alice",
        });
    
    });
    
    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()        
                .enabled(true)
                .realm("my-realm")
                .build());
    
            var user = new User("user", UserArgs.builder()        
                .email("bob@domain.com")
                .enabled(true)
                .firstName("Bob")
                .lastName("Bobson")
                .realmId(realm.id())
                .username("bob")
                .build());
    
            var userWithInitialPassword = new User("userWithInitialPassword", UserArgs.builder()        
                .email("alice@domain.com")
                .enabled(true)
                .firstName("Alice")
                .initialPassword(UserInitialPasswordArgs.builder()
                    .temporary(true)
                    .value("some password")
                    .build())
                .lastName("Aliceberg")
                .realmId(realm.id())
                .username("alice")
                .build());
    
        }
    }
    
    resources:
      realm:
        type: keycloak:Realm
        properties:
          enabled: true
          realm: my-realm
      user:
        type: keycloak:User
        properties:
          email: bob@domain.com
          enabled: true
          firstName: Bob
          lastName: Bobson
          realmId: ${realm.id}
          username: bob
      userWithInitialPassword:
        type: keycloak:User
        properties:
          email: alice@domain.com
          enabled: true
          firstName: Alice
          initialPassword:
            temporary: true
            value: some password
          lastName: Aliceberg
          realmId: ${realm.id}
          username: alice
    

    Argument Reference

    The following arguments are supported:

    • realm_id - (Required) The realm this user belongs to.
    • username - (Required) The unique username of this user.
    • initial_password (Optional) When given, the user’s initial password will be set. This attribute is only respected during initial user creation.
      • value (Required) The initial password.
      • temporary (Optional) If set to true, the initial password is set up for renewal on first use. Default to false.
    • enabled - (Optional) When false, this user cannot log in. Defaults to true.
    • email - (Optional) The user’s email.
    • first_name - (Optional) The user’s first name.
    • last_name - (Optional) The user’s last name.

    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:

    $ terraform import keycloak_user.user my-realm/60c3f971-b1d3-4b3a-9035-d16d7540a5e4
    

    Create User Resource

    new User(name: string, args: UserArgs, opts?: CustomResourceOptions);
    @overload
    def User(resource_name: str,
             opts: Optional[ResourceOptions] = None,
             attributes: Optional[Mapping[str, Any]] = 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)
    @overload
    def User(resource_name: str,
             args: UserArgs,
             opts: Optional[ResourceOptions] = None)
    func NewUser(ctx *Context, name string, args UserArgs, opts ...ResourceOption) (*User, error)
    public User(string name, UserArgs args, CustomResourceOptions? opts = null)
    public User(String name, UserArgs args)
    public User(String name, UserArgs args, CustomResourceOptions options)
    
    type: keycloak:User
    properties: # The arguments to resource properties.
    options: # 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.
    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.

    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

    The User resource accepts the following input properties:

    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, Any]] = 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.
    The following state arguments are supported:

    Supporting Types

    UserFederatedIdentity, UserFederatedIdentityArgs

    IdentityProvider string
    UserId string
    UserName string
    IdentityProvider string
    UserId string
    UserName string
    identityProvider String
    userId String
    userName String
    identityProvider string
    userId string
    userName string
    identityProvider String
    userId String
    userName String

    UserInitialPassword, UserInitialPasswordArgs

    Value string
    Temporary bool
    Value string
    Temporary bool
    value String
    temporary Boolean
    value string
    temporary boolean
    value String
    temporary Boolean

    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.3.1 published on Monday, Mar 11, 2024 by Pulumi