Skip to content

Commit edda219

Browse files
authored
gitlab_user: Do not set skip_confirmation on read (#491)
* gitlab_user: Do not set skip_confirmation on read gitlab_user tests refactor: Remove Password and SkipConfirmation fields from testAccGitlabUserExpectedAttributes struct These fields were not being checked in testAccCheckGitlabUserAttributes because they cannot be read. gitlab_user: Make skip_confirmation ForceNew, and more tests * gitlab_user: "password" and "reset_password" are ForceNew * Fix import tests verifying attributes which are not read
1 parent 327684e commit edda219

File tree

2 files changed

+128
-39
lines changed

2 files changed

+128
-39
lines changed

gitlab/resource_gitlab_user.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ func resourceGitlabUser() *schema.Resource {
3232
Type: schema.TypeString,
3333
Optional: true,
3434
Sensitive: true,
35+
ForceNew: true,
3536
},
3637
"email": {
3738
Type: schema.TypeString,
@@ -55,6 +56,7 @@ func resourceGitlabUser() *schema.Resource {
5556
Type: schema.TypeBool,
5657
Optional: true,
5758
Default: true,
59+
ForceNew: true,
5860
},
5961
"projects_limit": {
6062
Type: schema.TypeInt,
@@ -69,6 +71,7 @@ func resourceGitlabUser() *schema.Resource {
6971
"reset_password": {
7072
Type: schema.TypeBool,
7173
Optional: true,
74+
ForceNew: true,
7275
},
7376
"note": {
7477
Type: schema.TypeString,
@@ -87,7 +90,6 @@ func resourceGitlabUserSetToState(d *schema.ResourceData, user *gitlab.User) {
8790
d.Set("is_admin", user.IsAdmin)
8891
d.Set("is_external", user.External)
8992
d.Set("note", user.Note)
90-
d.Set("skip_confirmation", user.ConfirmedAt != nil && !user.ConfirmedAt.IsZero())
9193
}
9294

9395
func resourceGitlabUserCreate(d *schema.ResourceData, meta interface{}) error {

gitlab/resource_gitlab_user_test.go

Lines changed: 125 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -27,52 +27,89 @@ func TestAccGitlabUser_basic(t *testing.T) {
2727
Check: resource.ComposeTestCheckFunc(
2828
testAccCheckGitlabUserExists("gitlab_user.foo", &user),
2929
testAccCheckGitlabUserAttributes(&user, &testAccGitlabUserExpectedAttributes{
30-
Email: fmt.Sprintf("listest%[email protected]", rInt),
31-
Password: fmt.Sprintf("test%dtt", rInt),
32-
Username: fmt.Sprintf("listest%d", rInt),
33-
Name: fmt.Sprintf("foo %d", rInt),
34-
ProjectsLimit: 0,
35-
Admin: false,
36-
CanCreateGroup: false,
37-
SkipConfirmation: true,
38-
External: false,
30+
Email: fmt.Sprintf("listest%[email protected]", rInt),
31+
Username: fmt.Sprintf("listest%d", rInt),
32+
Name: fmt.Sprintf("foo %d", rInt),
33+
ProjectsLimit: 0,
34+
Admin: false,
35+
CanCreateGroup: false,
36+
External: false,
3937
}),
4038
),
4139
},
40+
{
41+
ResourceName: "gitlab_user.foo",
42+
ImportState: true,
43+
ImportStateVerify: true,
44+
ImportStateVerifyIgnore: []string{
45+
"password",
46+
"skip_confirmation",
47+
},
48+
},
4249
// Update the user to change the name, email, projects_limit and more
4350
{
4451
Config: testAccGitlabUserUpdateConfig(rInt),
4552
Check: resource.ComposeTestCheckFunc(
4653
testAccCheckGitlabUserExists("gitlab_user.foo", &user),
4754
testAccCheckGitlabUserAttributes(&user, &testAccGitlabUserExpectedAttributes{
48-
Email: fmt.Sprintf("listest%[email protected]", rInt),
49-
Password: fmt.Sprintf("test%dtt", rInt),
50-
Username: fmt.Sprintf("listest%d", rInt),
51-
Name: fmt.Sprintf("bar %d", rInt),
52-
ProjectsLimit: 10,
53-
Admin: true,
54-
CanCreateGroup: true,
55-
SkipConfirmation: false,
56-
External: false,
57-
Note: fmt.Sprintf("note%d", rInt),
55+
Email: fmt.Sprintf("listest%[email protected]", rInt),
56+
Username: fmt.Sprintf("listest%d", rInt),
57+
Name: fmt.Sprintf("bar %d", rInt),
58+
ProjectsLimit: 10,
59+
Admin: true,
60+
CanCreateGroup: true,
61+
External: false,
62+
Note: fmt.Sprintf("note%d", rInt),
5863
}),
5964
),
6065
},
66+
{
67+
ResourceName: "gitlab_user.foo",
68+
ImportState: true,
69+
ImportStateVerify: true,
70+
ImportStateVerifyIgnore: []string{
71+
"password",
72+
"skip_confirmation",
73+
},
74+
},
6175
// Update the user to put the name back
6276
{
6377
Config: testAccGitlabUserConfig(rInt),
6478
Check: resource.ComposeTestCheckFunc(
6579
testAccCheckGitlabUserExists("gitlab_user.foo", &user),
6680
testAccCheckGitlabUserAttributes(&user, &testAccGitlabUserExpectedAttributes{
67-
Email: fmt.Sprintf("listest%[email protected]", rInt),
68-
Password: fmt.Sprintf("test%dtt", rInt),
69-
Username: fmt.Sprintf("listest%d", rInt),
70-
Name: fmt.Sprintf("foo %d", rInt),
71-
ProjectsLimit: 0,
72-
Admin: false,
73-
CanCreateGroup: false,
74-
SkipConfirmation: false,
75-
External: false,
81+
Email: fmt.Sprintf("listest%[email protected]", rInt),
82+
Username: fmt.Sprintf("listest%d", rInt),
83+
Name: fmt.Sprintf("foo %d", rInt),
84+
ProjectsLimit: 0,
85+
Admin: false,
86+
CanCreateGroup: false,
87+
External: false,
88+
}),
89+
),
90+
},
91+
{
92+
ResourceName: "gitlab_user.foo",
93+
ImportState: true,
94+
ImportStateVerify: true,
95+
ImportStateVerifyIgnore: []string{
96+
"password",
97+
"skip_confirmation",
98+
},
99+
},
100+
// Update the user to disable skip confirmation
101+
{
102+
Config: testAccGitlabUserUpdateConfigNoSkipConfirmation(rInt),
103+
Check: resource.ComposeTestCheckFunc(
104+
testAccCheckGitlabUserExists("gitlab_user.foo", &user),
105+
testAccCheckGitlabUserAttributes(&user, &testAccGitlabUserExpectedAttributes{
106+
Email: fmt.Sprintf("listest%[email protected]", rInt),
107+
Username: fmt.Sprintf("listest%d", rInt),
108+
Name: fmt.Sprintf("foo %d", rInt),
109+
ProjectsLimit: 0,
110+
Admin: false,
111+
CanCreateGroup: false,
112+
External: false,
76113
}),
77114
),
78115
},
@@ -82,6 +119,32 @@ func TestAccGitlabUser_basic(t *testing.T) {
82119
ImportStateVerify: true,
83120
ImportStateVerifyIgnore: []string{
84121
"password",
122+
"skip_confirmation",
123+
},
124+
},
125+
// Update the user to initial config
126+
{
127+
Config: testAccGitlabUserConfig(rInt),
128+
Check: resource.ComposeTestCheckFunc(
129+
testAccCheckGitlabUserExists("gitlab_user.foo", &user),
130+
testAccCheckGitlabUserAttributes(&user, &testAccGitlabUserExpectedAttributes{
131+
Email: fmt.Sprintf("listest%[email protected]", rInt),
132+
Username: fmt.Sprintf("listest%d", rInt),
133+
Name: fmt.Sprintf("foo %d", rInt),
134+
ProjectsLimit: 0,
135+
Admin: false,
136+
CanCreateGroup: false,
137+
External: false,
138+
}),
139+
),
140+
},
141+
{
142+
ResourceName: "gitlab_user.foo",
143+
ImportState: true,
144+
ImportStateVerify: true,
145+
ImportStateVerifyIgnore: []string{
146+
"password",
147+
"skip_confirmation",
85148
},
86149
},
87150
},
@@ -107,6 +170,16 @@ func TestAccGitlabUser_password_reset(t *testing.T) {
107170
Config: testAccGitlabUserConfigPasswordReset(rInt),
108171
Check: testAccCheckGitlabUserExists("gitlab_user.foo", &user),
109172
},
173+
{
174+
ResourceName: "gitlab_user.foo",
175+
ImportState: true,
176+
ImportStateVerify: true,
177+
ImportStateVerifyIgnore: []string{
178+
"password",
179+
"reset_password",
180+
"skip_confirmation",
181+
},
182+
},
110183
},
111184
})
112185
}
@@ -136,16 +209,14 @@ func testAccCheckGitlabUserExists(n string, user *gitlab.User) resource.TestChec
136209
}
137210

138211
type testAccGitlabUserExpectedAttributes struct {
139-
Email string
140-
Password string
141-
Username string
142-
Name string
143-
ProjectsLimit int
144-
Admin bool
145-
CanCreateGroup bool
146-
SkipConfirmation bool
147-
External bool
148-
Note string
212+
Email string
213+
Username string
214+
Name string
215+
ProjectsLimit int
216+
Admin bool
217+
CanCreateGroup bool
218+
External bool
219+
Note string
149220
}
150221

151222
func testAccCheckGitlabUserAttributes(user *gitlab.User, want *testAccGitlabUserExpectedAttributes) resource.TestCheckFunc {
@@ -241,6 +312,22 @@ resource "gitlab_user" "foo" {
241312
`, rInt, rInt, rInt, rInt, rInt)
242313
}
243314

315+
func testAccGitlabUserUpdateConfigNoSkipConfirmation(rInt int) string {
316+
return fmt.Sprintf(`
317+
resource "gitlab_user" "foo" {
318+
name = "foo %d"
319+
username = "listest%d"
320+
password = "test%dtt"
321+
email = "listest%[email protected]"
322+
is_admin = false
323+
projects_limit = 0
324+
can_create_group = false
325+
is_external = false
326+
skip_confirmation = false
327+
}
328+
`, rInt, rInt, rInt, rInt)
329+
}
330+
244331
func testAccGitlabUserConfigPasswordReset(rInt int) string {
245332
return fmt.Sprintf(`
246333
resource "gitlab_user" "foo" {

0 commit comments

Comments
 (0)