Skip to content

Commit d0d2d62

Browse files
author
Adam Janis
committed
user: add is_external attribute
1 parent af02e06 commit d0d2d62

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

gitlab/resource_gitlab_user.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ func resourceGitlabUser() *schema.Resource {
5555
Optional: true,
5656
Default: 0,
5757
},
58+
"is_external": {
59+
Type: schema.TypeBool,
60+
Optional: true,
61+
Default: false,
62+
},
5863
},
5964
}
6065
}
@@ -77,6 +82,7 @@ func resourceGitlabUserCreate(d *schema.ResourceData, meta interface{}) error {
7782
Admin: gitlab.Bool(d.Get("is_admin").(bool)),
7883
CanCreateGroup: gitlab.Bool(d.Get("can_create_group").(bool)),
7984
SkipConfirmation: gitlab.Bool(d.Get("skip_confirmation").(bool)),
85+
External: gitlab.Bool(d.Get("is_external").(bool)),
8086
}
8187

8288
log.Printf("[DEBUG] create gitlab user %q", options.Username)
@@ -88,6 +94,7 @@ func resourceGitlabUserCreate(d *schema.ResourceData, meta interface{}) error {
8894

8995
d.SetId(fmt.Sprintf("%d", user.ID))
9096
d.Set("is_admin", user.IsAdmin)
97+
d.Set("is_external", user.External)
9198

9299
return resourceGitlabUserRead(d, meta)
93100
}
@@ -138,6 +145,10 @@ func resourceGitlabUserUpdate(d *schema.ResourceData, meta interface{}) error {
138145
options.ProjectsLimit = gitlab.Int(d.Get("projects_limit").(int))
139146
}
140147

148+
if d.HasChange("is_external") {
149+
options.Admin = gitlab.Bool(d.Get("is_external").(bool))
150+
}
151+
141152
log.Printf("[DEBUG] update gitlab user %s", d.Id())
142153

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

gitlab/resource_gitlab_user_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ func TestAccGitlabUser_basic(t *testing.T) {
3434
Admin: false,
3535
CanCreateGroup: false,
3636
SkipConfirmation: true,
37+
External: false,
3738
}),
3839
),
3940
},
@@ -51,6 +52,7 @@ func TestAccGitlabUser_basic(t *testing.T) {
5152
Admin: true,
5253
CanCreateGroup: true,
5354
SkipConfirmation: false,
55+
External: true,
5456
}),
5557
),
5658
},
@@ -68,6 +70,7 @@ func TestAccGitlabUser_basic(t *testing.T) {
6870
Admin: false,
6971
CanCreateGroup: false,
7072
SkipConfirmation: false,
73+
External: false,
7174
}),
7275
),
7376
},
@@ -108,6 +111,7 @@ type testAccGitlabUserExpectedAttributes struct {
108111
Admin bool
109112
CanCreateGroup bool
110113
SkipConfirmation bool
114+
External bool
111115
}
112116

113117
func testAccCheckGitlabUserAttributes(user *gitlab.User, want *testAccGitlabUserExpectedAttributes) resource.TestCheckFunc {
@@ -158,6 +162,7 @@ resource "gitlab_user" "foo" {
158162
is_admin = false
159163
projects_limit = 0
160164
can_create_group = false
165+
is_external = false
161166
}
162167
`, rInt, rInt, rInt, rInt)
163168
}
@@ -172,6 +177,7 @@ resource "gitlab_user" "foo" {
172177
is_admin = true
173178
projects_limit = 10
174179
can_create_group = true
180+
is_external = true
175181
}
176182
`, rInt, rInt, rInt, rInt)
177183
}

website/docs/r/user.html.markdown

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ resource "gitlab_user" "example" {
2222
is_admin = true
2323
projects_limit = 4
2424
can_create_group = false
25+
is_external = true
2526
}
2627
```
2728

@@ -46,6 +47,8 @@ for the user.
4647

4748
* `skip_confirmation` - (Optional) Boolean, defaults to true. Whether to skip confirmation.
4849

50+
* `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.
51+
4952
## Attributes Reference
5053

5154
The resource exports the following attributes:

0 commit comments

Comments
 (0)