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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 6 additions & 0 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy