Skip to content

Commit b1e2fd8

Browse files
authored
Merge pull request #262 from ilpianista/feature/optional-password
Make password and reset_password exclusive
2 parents ea1037d + 35d98f1 commit b1e2fd8

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

gitlab/resource_gitlab_user.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ func resourceGitlabUserCreate(d *schema.ResourceData, meta interface{}) error {
112112
ResetPassword: gitlab.Bool(d.Get("reset_password").(bool)),
113113
}
114114

115+
if *options.Password == "" && !*options.ResetPassword {
116+
return fmt.Errorf("At least one of either password or reset_password must be defined")
117+
}
118+
115119
log.Printf("[DEBUG] create gitlab user %q", *options.Username)
116120

117121
user, _, err := client.Users.CreateUser(options)

gitlab/resource_gitlab_user_test.go

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package gitlab
22

33
import (
44
"fmt"
5+
"regexp"
56
"strconv"
67
"testing"
78

@@ -96,7 +97,12 @@ func TestAccGitlabUser_password_reset(t *testing.T) {
9697
Providers: testAccProviders,
9798
CheckDestroy: testAccCheckGitlabGroupDestroy,
9899
Steps: []resource.TestStep{
99-
// Create a user
100+
// Test that either password or reset_password is needed
101+
{
102+
Config: testAccGitlabUserConfigWrong(rInt),
103+
ExpectError: regexp.MustCompile("At least one of either password or reset_password must be defined"),
104+
},
105+
// Create a user without a password
100106
{
101107
Config: testAccGitlabUserConfigPasswordReset(rInt),
102108
Check: testAccCheckGitlabUserExists("gitlab_user.foo", &user),
@@ -234,13 +240,18 @@ func testAccGitlabUserConfigPasswordReset(rInt int) string {
234240
resource "gitlab_user" "foo" {
235241
name = "foo %d"
236242
username = "listest%d"
237-
password = "test%dtt"
238243
email = "listest%[email protected]"
239-
is_admin = false
240-
projects_limit = 0
241-
can_create_group = false
242-
is_external = false
243244
reset_password = true
244245
}
245-
`, rInt, rInt, rInt, rInt)
246+
`, rInt, rInt, rInt)
247+
}
248+
249+
func testAccGitlabUserConfigWrong(rInt int) string {
250+
return fmt.Sprintf(`
251+
resource "gitlab_user" "foo" {
252+
name = "foo %d"
253+
username = "listest%d"
254+
email = "listest%[email protected]"
255+
}
256+
`, rInt, rInt, rInt)
246257
}

website/docs/r/user.html.markdown

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ description: |-
1111
This resource allows you to create and manage GitLab users.
1212
Note your provider will need to be configured with admin-level access for this resource to work.
1313

14+
-> **Note:** You must specify either `password` or `reset_password`.
15+
1416
## Example Usage
1517

1618
```hcl
@@ -35,10 +37,10 @@ The following arguments are supported:
3537

3638
* `username` - (Required) The username of the user.
3739

38-
* `password` - (Required) The password of the user.
39-
4040
* `email` - (Required) The e-mail address of the user.
4141

42+
* `password` - (Optional) The password of the user.
43+
4244
* `is_admin` - (Optional) Boolean, defaults to false. Whether to enable administrative priviledges
4345
for the user.
4446

0 commit comments

Comments
 (0)