@@ -30,9 +30,10 @@ func TestAccGitlabProjectAccessToken_basic(t *testing.T) {
30
30
Check : resource .ComposeTestCheckFunc (
31
31
testAccCheckGitlabProjectAccessTokenExists ("gitlab_project_access_token.bar" , & pat ),
32
32
testAccCheckGitlabProjectAccessTokenAttributes (& pat , & testAccGitlabProjectAccessTokenExpectedAttributes {
33
- name : "my project token" ,
34
- scopes : map [string ]bool {"read_repository" : true , "api" : true , "write_repository" : true , "read_api" : true },
35
- expiresAt : "2022-04-01" ,
33
+ name : "my project token" ,
34
+ scopes : map [string ]bool {"read_repository" : true , "api" : true , "write_repository" : true , "read_api" : true },
35
+ expiresAt : "2022-04-01" ,
36
+ accessLevel : accessLevelValueToName [gitlab .MaintainerPermissions ], // default permission on gitlab side when unspecified
36
37
}),
37
38
),
38
39
},
@@ -92,6 +93,56 @@ func TestAccGitlabProjectAccessToken_basic(t *testing.T) {
92
93
})
93
94
}
94
95
96
+ func TestAccGitlabProjectAccessToken_accessLevel (t * testing.T ) {
97
+ var pat testAccGitlabProjectAccessTokenWrapper
98
+ rInt := acctest .RandInt ()
99
+
100
+ testAccGitlabProjectStart (t )
101
+
102
+ resource .Test (t , resource.TestCase {
103
+ PreCheck : func () { testAccPreCheck (t ) },
104
+ ProviderFactories : providerFactories ,
105
+ CheckDestroy : testAccCheckGitlabProjectAccessTokenDestroy ,
106
+ Steps : []resource.TestStep {
107
+ // Create a project and a Project Access Token
108
+ {
109
+ Config : testAccGitlabProjectAccessTokenConfigWithAccessLevel (rInt , accessLevelValueToName [gitlab .MaintainerPermissions ]),
110
+ Check : resource .ComposeTestCheckFunc (
111
+ testAccCheckGitlabProjectAccessTokenExists ("gitlab_project_access_token.bar" , & pat ),
112
+ testAccCheckGitlabProjectAccessTokenAttributes (& pat , & testAccGitlabProjectAccessTokenExpectedAttributes {
113
+ name : "my project token" ,
114
+ scopes : map [string ]bool {"read_repository" : true , "api" : true , "write_repository" : true , "read_api" : true },
115
+ expiresAt : "2022-04-01" ,
116
+ accessLevel : accessLevelValueToName [gitlab .MaintainerPermissions ],
117
+ }),
118
+ ),
119
+ },
120
+ // Update the Project Access Token to change the parameters
121
+ {
122
+ Config : testAccGitlabProjectAccessTokenConfigWithAccessLevel (rInt , accessLevelValueToName [gitlab .DeveloperPermissions ]),
123
+ Check : resource .ComposeTestCheckFunc (
124
+ testAccCheckGitlabProjectAccessTokenExists ("gitlab_project_access_token.bar" , & pat ),
125
+ testAccCheckGitlabProjectAccessTokenAttributes (& pat , & testAccGitlabProjectAccessTokenExpectedAttributes {
126
+ name : "my project token" ,
127
+ scopes : map [string ]bool {"read_repository" : true , "api" : true , "write_repository" : true , "read_api" : true },
128
+ expiresAt : "2022-04-01" ,
129
+ accessLevel : accessLevelValueToName [gitlab .DeveloperPermissions ],
130
+ }),
131
+ ),
132
+ },
133
+ // Verify import
134
+ {
135
+ ResourceName : "gitlab_project_access_token.bar" ,
136
+ ImportState : true ,
137
+ ImportStateVerify : true ,
138
+ ImportStateVerifyIgnore : []string {
139
+ // the token is only known during creating. We explicitly mention this limitation in the docs.
140
+ "token" ,
141
+ },
142
+ },
143
+ }})
144
+ }
145
+
95
146
func testAccCheckGitlabProjectAccessTokenDoesNotExist (pat * testAccGitlabProjectAccessTokenWrapper ) resource.TestCheckFunc {
96
147
return func (s * terraform.State ) error {
97
148
return gomega .InterceptGomegaFailure (func () {
@@ -155,9 +206,10 @@ func testAccCheckGitlabProjectAccessTokenExists(n string, pat *testAccGitlabProj
155
206
}
156
207
157
208
type testAccGitlabProjectAccessTokenExpectedAttributes struct {
158
- name string
159
- scopes map [string ]bool
160
- expiresAt string
209
+ name string
210
+ scopes map [string ]bool
211
+ expiresAt string
212
+ accessLevel string
161
213
}
162
214
163
215
type testAccGitlabProjectAccessTokenWrapper struct {
@@ -304,3 +356,24 @@ resource "gitlab_project_variable" "var" {
304
356
305
357
` , rInt )
306
358
}
359
+
360
+ func testAccGitlabProjectAccessTokenConfigWithAccessLevel (rInt int , level string ) string {
361
+ return fmt .Sprintf (`
362
+ resource "gitlab_project" "foo" {
363
+ name = "foo-%d"
364
+ description = "Terraform acceptance tests"
365
+
366
+ # So that acceptance tests can be run in a gitlab organization
367
+ # with no billing
368
+ visibility_level = "public"
369
+ }
370
+
371
+ resource "gitlab_project_access_token" "bar" {
372
+ name = "my project token"
373
+ project = gitlab_project.foo.id
374
+ expires_at = "2022-04-01"
375
+ scopes = ["read_repository" , "api", "write_repository", "read_api"]
376
+ access_level = "%s"
377
+ }
378
+ ` , rInt , level )
379
+ }
0 commit comments