Skip to content

Commit 20582af

Browse files
committed
Support the note field for the user resource/data
1 parent a690c44 commit 20582af

File tree

5 files changed

+26
-1
lines changed

5 files changed

+26
-1
lines changed

docs/data-sources/users.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ The following attributes are exported:
5757
* `provider` - The UID provider of the user.
5858
* `organization` - The organization of the user.
5959
* `two_factor_enabled` - Whether user's two factor auth is enabled.
60+
* `note` - The note associated to the user.
6061
* `avatar_url` - The avatar URL of the user.
6162
* `bio` - The bio of the user.
6263
* `location` - The location of the user.

docs/resources/user.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ for the user.
4444

4545
* `is_external` - (Optional) Boolean, defaults to false. Whether a user has access only to some internal or private projects. External users can only access projects to which they are explicitly granted access.
4646

47+
* `note` - (Optional) The note associated to the user.
48+
4749
* `reset_password` - (Optional) Boolean, defaults to false. Send user password reset link.
4850

4951
## Attributes Reference

gitlab/data_source_gitlab_user.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ func dataSourceGitlabUser() *schema.Resource {
8484
Type: schema.TypeBool,
8585
Computed: true,
8686
},
87+
"note": {
88+
Type: schema.TypeString,
89+
Computed: true,
90+
},
8791
"user_provider": {
8892
Type: schema.TypeString,
8993
Computed: true,
@@ -198,6 +202,7 @@ func dataSourceGitlabUserRead(d *schema.ResourceData, meta interface{}) error {
198202
d.Set("created_at", user.CreatedAt)
199203
d.Set("organization", user.Organization)
200204
d.Set("two_factor_enabled", user.TwoFactorEnabled)
205+
d.Set("note", user.Note)
201206
d.Set("provider", user.Provider)
202207
d.Set("avatar_url", user.AvatarURL)
203208
d.Set("bio", user.Bio)

gitlab/resource_gitlab_user.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ func resourceGitlabUser() *schema.Resource {
6868
Type: schema.TypeBool,
6969
Optional: true,
7070
},
71+
"note": {
72+
Type: schema.TypeString,
73+
Optional: true,
74+
},
7175
},
7276
}
7377
}
@@ -80,6 +84,7 @@ func resourceGitlabUserSetToState(d *schema.ResourceData, user *gitlab.User) {
8084
d.Set("email", user.Email)
8185
d.Set("is_admin", user.IsAdmin)
8286
d.Set("is_external", user.External)
87+
d.Set("note", user.Note)
8388
d.Set("skip_confirmation", user.ConfirmedAt != nil && !user.ConfirmedAt.IsZero())
8489
}
8590

@@ -96,6 +101,7 @@ func resourceGitlabUserCreate(d *schema.ResourceData, meta interface{}) error {
96101
SkipConfirmation: gitlab.Bool(d.Get("skip_confirmation").(bool)),
97102
External: gitlab.Bool(d.Get("is_external").(bool)),
98103
ResetPassword: gitlab.Bool(d.Get("reset_password").(bool)),
104+
Note: gitlab.String(d.Get("note").(string)),
99105
}
100106

101107
if *options.Password == "" && !*options.ResetPassword {
@@ -163,6 +169,10 @@ func resourceGitlabUserUpdate(d *schema.ResourceData, meta interface{}) error {
163169
options.External = gitlab.Bool(d.Get("is_external").(bool))
164170
}
165171

172+
if d.HasChange("note") {
173+
options.Note = gitlab.String(d.Get("note").(string))
174+
}
175+
166176
log.Printf("[DEBUG] update gitlab user %s", d.Id())
167177

168178
id, _ := strconv.Atoi(d.Id())

gitlab/resource_gitlab_user_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ func TestAccGitlabUser_basic(t *testing.T) {
5454
CanCreateGroup: true,
5555
SkipConfirmation: false,
5656
External: false,
57+
Note: fmt.Sprintf("note%d", rInt),
5758
}),
5859
),
5960
},
@@ -144,6 +145,7 @@ type testAccGitlabUserExpectedAttributes struct {
144145
CanCreateGroup bool
145146
SkipConfirmation bool
146147
External bool
148+
Note string
147149
}
148150

149151
func testAccCheckGitlabUserAttributes(user *gitlab.User, want *testAccGitlabUserExpectedAttributes) resource.TestCheckFunc {
@@ -168,6 +170,10 @@ func testAccCheckGitlabUserAttributes(user *gitlab.User, want *testAccGitlabUser
168170
return fmt.Errorf("got is_external %t; want %t", user.External, want.External)
169171
}
170172

173+
if user.Note != want.Note {
174+
return fmt.Errorf("got note %q; want %q", user.Note, want.Note)
175+
}
176+
171177
if user.IsAdmin != want.Admin {
172178
return fmt.Errorf("got is_admin %t; want %t", user.IsAdmin, want.Admin)
173179
}
@@ -230,8 +236,9 @@ resource "gitlab_user" "foo" {
230236
projects_limit = 10
231237
can_create_group = true
232238
is_external = false
239+
note = "note%d"
233240
}
234-
`, rInt, rInt, rInt, rInt)
241+
`, rInt, rInt, rInt, rInt, rInt)
235242
}
236243

237244
func testAccGitlabUserConfigPasswordReset(rInt int) string {

0 commit comments

Comments
 (0)