Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion integration/user-test/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ resource "coderd_user" "ethan2" {
username = "${data.coderd_user.ethan.username}2"
name = "${data.coderd_user.ethan.name}2"
email = "${data.coderd_user.ethan.email}.au"
login_type = "${data.coderd_user.ethan.login_type}"
roles = data.coderd_user.ethan.roles
suspended = data.coderd_user.ethan.suspended
}
Expand Down
6 changes: 6 additions & 0 deletions internal/provider/user_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func (r *UserResource) Schema(ctx context.Context, req resource.SchemaRequest, r
MarkdownDescription: "Display name of the user. Defaults to username.",
Required: false,
Optional: true,
// Defaulted in Create
},
"email": schema.StringAttribute{
MarkdownDescription: "Email address of the user.",
Expand Down Expand Up @@ -167,6 +168,10 @@ func (r *UserResource) Create(ctx context.Context, req resource.CreateRequest, r
if data.LoginType.ValueString() != "" {
loginType = codersdk.LoginType(data.LoginType.ValueString())
}
if loginType == codersdk.LoginTypePassword && data.Password.ValueString() == "" {
resp.Diagnostics.AddError("Data Error", "Password is required when login_type is 'password'")
return
}
user, err := client.CreateUser(ctx, codersdk.CreateUserRequest{
Email: data.Email.ValueString(),
Username: data.Username.ValueString(),
Expand Down Expand Up @@ -197,6 +202,7 @@ func (r *UserResource) Create(ctx context.Context, req resource.CreateRequest, r
return
}
tflog.Trace(ctx, "successfully updated user profile")
data.Name = types.StringValue(user.Name)

var roles []string
resp.Diagnostics.Append(
Expand Down