Skip to content

Commit ee5c4e5

Browse files
fix: set display name during create (#24)
1 parent a4ec0db commit ee5c4e5

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

integration/user-test/main.tf

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ resource "coderd_user" "ethan2" {
2525
username = "${data.coderd_user.ethan.username}2"
2626
name = "${data.coderd_user.ethan.name}2"
2727
email = "${data.coderd_user.ethan.email}.au"
28-
login_type = "${data.coderd_user.ethan.login_type}"
2928
roles = data.coderd_user.ethan.roles
3029
suspended = data.coderd_user.ethan.suspended
3130
}

internal/provider/user_resource.go

+6
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ func (r *UserResource) Schema(ctx context.Context, req resource.SchemaRequest, r
7676
MarkdownDescription: "Display name of the user. Defaults to username.",
7777
Required: false,
7878
Optional: true,
79+
// Defaulted in Create
7980
},
8081
"email": schema.StringAttribute{
8182
MarkdownDescription: "Email address of the user.",
@@ -167,6 +168,10 @@ func (r *UserResource) Create(ctx context.Context, req resource.CreateRequest, r
167168
if data.LoginType.ValueString() != "" {
168169
loginType = codersdk.LoginType(data.LoginType.ValueString())
169170
}
171+
if loginType == codersdk.LoginTypePassword && data.Password.ValueString() == "" {
172+
resp.Diagnostics.AddError("Data Error", "Password is required when login_type is 'password'")
173+
return
174+
}
170175
user, err := client.CreateUser(ctx, codersdk.CreateUserRequest{
171176
Email: data.Email.ValueString(),
172177
Username: data.Username.ValueString(),
@@ -197,6 +202,7 @@ func (r *UserResource) Create(ctx context.Context, req resource.CreateRequest, r
197202
return
198203
}
199204
tflog.Trace(ctx, "successfully updated user profile")
205+
data.Name = types.StringValue(user.Name)
200206

201207
var roles []string
202208
resp.Diagnostics.Append(

0 commit comments

Comments
 (0)