Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4813553

Browse files
committed
feat: allow email updates in user resources
1 parent375a205 commit4813553

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

‎internal/provider/user_resource.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ func (r *UserResource) Schema(ctx context.Context, req resource.SchemaRequest, r
8181
"email": schema.StringAttribute{
8282
MarkdownDescription:"Email address of the user.",
8383
Required:true,
84+
PlanModifiers: []planmodifier.String{
85+
stringplanmodifier.RequiresReplace(),
86+
},
8487
},
8588
"roles": schema.SetAttribute{
8689
MarkdownDescription:"Roles assigned to the user. Valid roles are 'owner', 'template-admin', 'user-admin', and 'auditor'.",

‎internal/provider/user_resource_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
"github.com/coder/terraform-provider-coderd/integration"
1212
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
13+
"github.com/hashicorp/terraform-plugin-testing/terraform"
1314
"github.com/stretchr/testify/require"
1415
)
1516

@@ -35,6 +36,10 @@ func TestAccUserResource(t *testing.T) {
3536
cfg2.Username=PtrTo("exampleNew")
3637
cfg2.Name=PtrTo("Example User New")
3738

39+
cfg3:=cfg1
40+
cfg3.Email=PtrTo("example2@coder.com")
41+
42+
varuserIdstring
3843
resource.Test(t, resource.TestCase{
3944
PreCheck:func() {testAccPreCheck(t) },
4045
ProtoV6ProviderFactories:testAccProtoV6ProviderFactories,
@@ -68,6 +73,15 @@ func TestAccUserResource(t *testing.T) {
6873
Check:resource.ComposeAggregateTestCheckFunc(
6974
resource.TestCheckResourceAttr("coderd_user.test","username","exampleNew"),
7075
resource.TestCheckResourceAttr("coderd_user.test","name","Example User New"),
76+
testAccIdChanged("coderd_user.test",&userId),
77+
),
78+
},
79+
// Replace testing
80+
{
81+
Config:cfg3.String(t),
82+
Check:resource.ComposeAggregateTestCheckFunc(
83+
resource.TestCheckResourceAttr("coderd_user.test","email","example2@coder.com"),
84+
testAccIdChanged("coderd_user.test",&userId),
7185
),
7286
},
7387
// Delete testing automatically occurs in TestCase
@@ -151,3 +165,24 @@ resource "coderd_user" "test" {
151165

152166
returnbuf.String()
153167
}
168+
169+
// Check if the id has changed since the last time this check function was run.
170+
functestAccIdChanged(resourceNamestring,id*string) resource.TestCheckFunc {
171+
returnfunc(s*terraform.State)error {
172+
rs,ok:=s.RootModule().Resources[resourceName]
173+
if!ok {
174+
returnfmt.Errorf("Resource %s not found",resourceName)
175+
}
176+
ifrs.Primary.ID=="" {
177+
returnfmt.Errorf("No ID is set")
178+
}
179+
if*id=="" {
180+
*id=rs.Primary.ID
181+
returnnil
182+
}
183+
ifrs.Primary.ID==*id {
184+
returnfmt.Errorf("ID did not change from %s",rs.Primary.ID)
185+
}
186+
returnnil
187+
}
188+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp