1. Packages
  2. Auth0 Provider
  3. API Docs
  4. UserRoles
Auth0 v3.17.1 published on Tuesday, Apr 15, 2025 by Pulumi

auth0.UserRoles

Explore with Pulumi AI

With this resource, you can manage assigned roles for a user.

!> This resource manages all the roles assigned to a user. In contrast, the auth0.UserRole resource only appends a role to a user. To avoid potential issues, it is recommended not to use this resource in conjunction with the auth0.UserRole resource when managing roles for the same user id.

Example Usage

import * as pulumi from "@pulumi/pulumi";
import * as auth0 from "@pulumi/auth0";

// Example:
const admin = new auth0.Role("admin", {
    name: "admin",
    description: "Administrator",
});
const user = new auth0.User("user", {
    connectionName: "Username-Password-Authentication",
    username: "unique_username",
    name: "Firstname Lastname",
    email: "test@test.com",
    password: "passpass$12$12",
});
const userRoles = new auth0.UserRoles("user_roles", {
    userId: user.id,
    roles: [admin.id],
});
Copy
import pulumi
import pulumi_auth0 as auth0

# Example:
admin = auth0.Role("admin",
    name="admin",
    description="Administrator")
user = auth0.User("user",
    connection_name="Username-Password-Authentication",
    username="unique_username",
    name="Firstname Lastname",
    email="test@test.com",
    password="passpass$12$12")
user_roles = auth0.UserRoles("user_roles",
    user_id=user.id,
    roles=[admin.id])
Copy
package main

import (
	"github.com/pulumi/pulumi-auth0/sdk/v3/go/auth0"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		// Example:
		admin, err := auth0.NewRole(ctx, "admin", &auth0.RoleArgs{
			Name:        pulumi.String("admin"),
			Description: pulumi.String("Administrator"),
		})
		if err != nil {
			return err
		}
		user, err := auth0.NewUser(ctx, "user", &auth0.UserArgs{
			ConnectionName: pulumi.String("Username-Password-Authentication"),
			Username:       pulumi.String("unique_username"),
			Name:           pulumi.String("Firstname Lastname"),
			Email:          pulumi.String("test@test.com"),
			Password:       pulumi.String("passpass$12$12"),
		})
		if err != nil {
			return err
		}
		_, err = auth0.NewUserRoles(ctx, "user_roles", &auth0.UserRolesArgs{
			UserId: user.ID(),
			Roles: pulumi.StringArray{
				admin.ID(),
			},
		})
		if err != nil {
			return err
		}
		return nil
	})
}
Copy
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Auth0 = Pulumi.Auth0;

return await Deployment.RunAsync(() => 
{
    // Example:
    var admin = new Auth0.Role("admin", new()
    {
        Name = "admin",
        Description = "Administrator",
    });

    var user = new Auth0.User("user", new()
    {
        ConnectionName = "Username-Password-Authentication",
        Username = "unique_username",
        Name = "Firstname Lastname",
        Email = "test@test.com",
        Password = "passpass$12$12",
    });

    var userRoles = new Auth0.UserRoles("user_roles", new()
    {
        UserId = user.Id,
        Roles = new[]
        {
            admin.Id,
        },
    });

});
Copy
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.auth0.Role;
import com.pulumi.auth0.RoleArgs;
import com.pulumi.auth0.User;
import com.pulumi.auth0.UserArgs;
import com.pulumi.auth0.UserRoles;
import com.pulumi.auth0.UserRolesArgs;
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) {
        // Example:
        var admin = new Role("admin", RoleArgs.builder()
            .name("admin")
            .description("Administrator")
            .build());

        var user = new User("user", UserArgs.builder()
            .connectionName("Username-Password-Authentication")
            .username("unique_username")
            .name("Firstname Lastname")
            .email("test@test.com")
            .password("passpass$12$12")
            .build());

        var userRoles = new UserRoles("userRoles", UserRolesArgs.builder()
            .userId(user.id())
            .roles(admin.id())
            .build());

    }
}
Copy
resources:
  # Example:
  admin:
    type: auth0:Role
    properties:
      name: admin
      description: Administrator
  user:
    type: auth0:User
    properties:
      connectionName: Username-Password-Authentication
      username: unique_username
      name: Firstname Lastname
      email: test@test.com
      password: passpass$12$12
  userRoles:
    type: auth0:UserRoles
    name: user_roles
    properties:
      userId: ${user.id}
      roles:
        - ${admin.id}
Copy

Create UserRoles Resource

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

Constructor syntax

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

@overload
def UserRoles(resource_name: str,
              opts: Optional[ResourceOptions] = None,
              roles: Optional[Sequence[str]] = None,
              user_id: Optional[str] = None)
func NewUserRoles(ctx *Context, name string, args UserRolesArgs, opts ...ResourceOption) (*UserRoles, error)
public UserRoles(string name, UserRolesArgs args, CustomResourceOptions? opts = null)
public UserRoles(String name, UserRolesArgs args)
public UserRoles(String name, UserRolesArgs args, CustomResourceOptions options)
type: auth0:UserRoles
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. UserRolesArgs
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. UserRolesArgs
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. UserRolesArgs
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. UserRolesArgs
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. UserRolesArgs
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 userRolesResource = new Auth0.UserRoles("userRolesResource", new()
{
    Roles = new[]
    {
        "string",
    },
    UserId = "string",
});
Copy
example, err := auth0.NewUserRoles(ctx, "userRolesResource", &auth0.UserRolesArgs{
	Roles: pulumi.StringArray{
		pulumi.String("string"),
	},
	UserId: pulumi.String("string"),
})
Copy
var userRolesResource = new UserRoles("userRolesResource", UserRolesArgs.builder()
    .roles("string")
    .userId("string")
    .build());
Copy
user_roles_resource = auth0.UserRoles("userRolesResource",
    roles=["string"],
    user_id="string")
Copy
const userRolesResource = new auth0.UserRoles("userRolesResource", {
    roles: ["string"],
    userId: "string",
});
Copy
type: auth0:UserRoles
properties:
    roles:
        - string
    userId: string
Copy

UserRoles 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 UserRoles resource accepts the following input properties:

Roles This property is required. List<string>
Set of IDs of roles assigned to the user.
UserId
This property is required.
Changes to this property will trigger replacement.
string
ID of the user.
Roles This property is required. []string
Set of IDs of roles assigned to the user.
UserId
This property is required.
Changes to this property will trigger replacement.
string
ID of the user.
roles This property is required. List<String>
Set of IDs of roles assigned to the user.
userId
This property is required.
Changes to this property will trigger replacement.
String
ID of the user.
roles This property is required. string[]
Set of IDs of roles assigned to the user.
userId
This property is required.
Changes to this property will trigger replacement.
string
ID of the user.
roles This property is required. Sequence[str]
Set of IDs of roles assigned to the user.
user_id
This property is required.
Changes to this property will trigger replacement.
str
ID of the user.
roles This property is required. List<String>
Set of IDs of roles assigned to the user.
userId
This property is required.
Changes to this property will trigger replacement.
String
ID of the user.

Outputs

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

Get an existing UserRoles 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?: UserRolesState, opts?: CustomResourceOptions): UserRoles
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        roles: Optional[Sequence[str]] = None,
        user_id: Optional[str] = None) -> UserRoles
func GetUserRoles(ctx *Context, name string, id IDInput, state *UserRolesState, opts ...ResourceOption) (*UserRoles, error)
public static UserRoles Get(string name, Input<string> id, UserRolesState? state, CustomResourceOptions? opts = null)
public static UserRoles get(String name, Output<String> id, UserRolesState state, CustomResourceOptions options)
resources:  _:    type: auth0:UserRoles    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:
Roles List<string>
Set of IDs of roles assigned to the user.
UserId Changes to this property will trigger replacement. string
ID of the user.
Roles []string
Set of IDs of roles assigned to the user.
UserId Changes to this property will trigger replacement. string
ID of the user.
roles List<String>
Set of IDs of roles assigned to the user.
userId Changes to this property will trigger replacement. String
ID of the user.
roles string[]
Set of IDs of roles assigned to the user.
userId Changes to this property will trigger replacement. string
ID of the user.
roles Sequence[str]
Set of IDs of roles assigned to the user.
user_id Changes to this property will trigger replacement. str
ID of the user.
roles List<String>
Set of IDs of roles assigned to the user.
userId Changes to this property will trigger replacement. String
ID of the user.

Import

This resource can be imported using the user ID.

Example:

$ pulumi import auth0:index/userRoles:UserRoles user_roles "auth0|111111111111111111111111"
Copy

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

Package Details

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