Skip to content

Commit 2d7f0eb

Browse files
authored
Merge pull request #819 from timofurrer/feature/align-access-level-794
Aligns the *Access Level* situation in this providers with the upstream API. Closes #794
2 parents be59cd1 + 385c892 commit 2d7f0eb

27 files changed

+306
-233
lines changed

docs/resources/branch_protection.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ resource "gitlab_branch_protection" "main" {
5858
### Required
5959

6060
- **branch** (String) Name of the branch.
61-
- **merge_access_level** (String) Access levels allowed to merge. Valid values are: `no one`, `developer`, `maintainer`, `admin`.
61+
- **merge_access_level** (String) Access levels allowed to merge. Valid values are: `no one`, `developer`, `maintainer`.
6262
- **project** (String) The id of the project.
63-
- **push_access_level** (String) Access levels allowed to push. Valid values are: `no one`, `developer`, `maintainer`, `admin`.
63+
- **push_access_level** (String) Access levels allowed to push. Valid values are: `no one`, `developer`, `maintainer`.
6464

6565
### Optional
6666

docs/resources/group_ldap_link.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ This resource allows you to add an LDAP link to an existing GitLab group.
1616
resource "gitlab_group_ldap_link" "test" {
1717
group_id = "12345"
1818
cn = "testuser"
19-
access_level = "developer"
19+
group_access = "developer"
2020
ldap_provider = "ldapmain"
2121
}
2222
```
@@ -26,14 +26,15 @@ resource "gitlab_group_ldap_link" "test" {
2626

2727
### Required
2828

29-
- **access_level** (String) Acceptable values are: guest, minimal, reporter, developer, maintainer, owner.
3029
- **cn** (String) The CN of the LDAP group to link with.
3130
- **group_id** (String) The id of the GitLab group.
3231
- **ldap_provider** (String) The name of the LDAP provider as stored in the GitLab database.
3332

3433
### Optional
3534

35+
- **access_level** (String, Deprecated) Minimum access level for members of the LDAP group. Valid values are: `no one`, `minimal`, `guest`, `reporter`, `developer`, `maintainer`, `owner`, `master`
3636
- **force** (Boolean) If true, then delete and replace an existing LDAP link if one exists.
37+
- **group_access** (String) Minimum access level for members of the LDAP group. Valid values are: `no one`, `minimal`, `guest`, `reporter`, `developer`, `maintainer`, `owner`, `master`
3738
- **id** (String) The ID of this resource.
3839

3940
## Import

docs/resources/group_membership.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ resource "gitlab_group_membership" "test" {
2626

2727
### Required
2828

29-
- **access_level** (String) Acceptable values are: guest, minimal, reporter, developer, maintainer, owner.
29+
- **access_level** (String) Access level for the member. Valid values are: `no one`, `minimal`, `guest`, `reporter`, `developer`, `maintainer`, `owner`, `master`.
3030
- **group_id** (String) The id of the group.
3131
- **user_id** (Number) The id of the user.
3232

docs/resources/group_share_group.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ resource "gitlab_group_share_group" "test" {
2626

2727
### Required
2828

29-
- **group_access** (String) One of five levels of access to the group.
29+
- **group_access** (String) The access level to grant the group. Valid values are: `no one`, `minimal`, `guest`, `reporter`, `developer`, `maintainer`, `owner`, `master`
3030
- **group_id** (String) The id of the main group.
3131
- **share_group_id** (Number) The id of an additional group which will be shared with the main group.
3232

docs/resources/project_membership.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ resource "gitlab_project_membership" "example" {
3131

3232
### Required
3333

34-
- **access_level** (String) One of five levels of access to the project.
34+
- **access_level** (String) The access level for the member. Valid values are: `no one`, `minimal`, `guest`, `reporter`, `developer`, `maintainer`, `master`
3535
- **project_id** (String) The id of the project.
3636
- **user_id** (Number) The id of the user.
3737

docs/resources/project_share_group.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ This resource allows you to share a project with a group
1616
resource "gitlab_project_share_group" "test" {
1717
project_id = "12345"
1818
group_id = 1337
19-
access_level = "guest"
19+
group_access = "guest"
2020
}
2121
```
2222

@@ -25,12 +25,13 @@ resource "gitlab_project_share_group" "test" {
2525

2626
### Required
2727

28-
- **access_level** (String) One of five levels of access to the project.
2928
- **group_id** (Number) The id of the group.
3029
- **project_id** (String) The id of the project.
3130

3231
### Optional
3332

33+
- **access_level** (String, Deprecated) The access level to grant the group for the project. Valid values are: `no one`, `minimal`, `guest`, `reporter`, `developer`, `maintainer`, `master`
34+
- **group_access** (String) The access level to grant the group for the project. Valid values are: `no one`, `minimal`, `guest`, `reporter`, `developer`, `maintainer`, `master`
3435
- **id** (String) The ID of this resource.
3536

3637
## Import

docs/resources/tag_protection.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ resource "gitlab_tag_protection" "TagProtect" {
2525

2626
### Required
2727

28-
- **create_access_level** (String) One of five levels of access to the project.
28+
- **create_access_level** (String) Access levels which are allowed to create. Valid values are: `no one`, `developer`, `maintainer`.
2929
- **project** (String) The id of the project.
3030
- **tag** (String) Name of the tag or wildcard.
3131

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
resource "gitlab_group_ldap_link" "test" {
22
group_id = "12345"
33
cn = "testuser"
4-
access_level = "developer"
4+
group_access = "developer"
55
ldap_provider = "ldapmain"
66
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
resource "gitlab_project_share_group" "test" {
22
project_id = "12345"
33
group_id = 1337
4-
access_level = "guest"
4+
group_access = "guest"
55
}

gitlab/access_level_helpers.go

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package gitlab
2+
3+
import (
4+
"github.com/xanzy/go-gitlab"
5+
)
6+
7+
// NOTE:
8+
// The access level story in the GitLab API is a bit tricky.
9+
// There are different resources using the same access level names
10+
// with an identical mapping to int ids. As also defined in the
11+
// `gitlab.AccessLevelValue` types. However, different endpoints
12+
// allow all of them or just a subset. There is also endpoints
13+
// defining an additional `admin` access level, which is nowhere
14+
// documented and probably not used at all - this provider ignores it.
15+
// Point being, be careful when using them in a resource or data source
16+
// and consult the upstream API docs to verify what's possible and keep
17+
// your fingers crossed it's correct :)
18+
19+
// see the source of truth for `accessLevelNameToValue` and `accessLevelValueToName`
20+
// here: https://docs.gitlab.com/ee/api/members.html#valid-access-levels
21+
var validGroupAccessLevelNames = []string{
22+
"no one",
23+
"minimal",
24+
"guest",
25+
"reporter",
26+
"developer",
27+
"maintainer",
28+
"owner",
29+
30+
// Deprecated and should be removed in v4 of this provider
31+
"master",
32+
}
33+
var validProjectAccessLevelNames = []string{
34+
"no one",
35+
"minimal",
36+
"guest",
37+
"reporter",
38+
"developer",
39+
"maintainer",
40+
41+
// Deprecated and should be removed in v4 of this provider
42+
"master",
43+
}
44+
45+
// NOTE(TF): the documentation here https://docs.gitlab.com/ee/api/protected_branches.html
46+
// mentions an `60 => Admin access` level, but it actually seems to not exist.
47+
// Ignoring here that I've every read about this ...
48+
var validProtectedBranchTagAccessLevelNames = []string{
49+
"no one", "developer", "maintainer",
50+
}
51+
52+
var accessLevelNameToValue = map[string]gitlab.AccessLevelValue{
53+
"no one": gitlab.NoPermissions,
54+
"minimal": gitlab.MinimalAccessPermissions,
55+
"guest": gitlab.GuestPermissions,
56+
"reporter": gitlab.ReporterPermissions,
57+
"developer": gitlab.DeveloperPermissions,
58+
"maintainer": gitlab.MaintainerPermissions,
59+
"owner": gitlab.OwnerPermission,
60+
61+
// Deprecated and should be removed in v4 of this provider
62+
"master": gitlab.MaintainerPermissions,
63+
}
64+
65+
var accessLevelValueToName = map[gitlab.AccessLevelValue]string{
66+
gitlab.NoPermissions: "no one",
67+
gitlab.MinimalAccessPermissions: "minimal",
68+
gitlab.GuestPermissions: "guest",
69+
gitlab.ReporterPermissions: "reporter",
70+
gitlab.DeveloperPermissions: "developer",
71+
gitlab.MaintainerPermissions: "maintainer",
72+
gitlab.OwnerPermissions: "owner",
73+
}

0 commit comments

Comments
 (0)