Skip to content

Commit dee9634

Browse files
committed
Code review changes
1 parent c835ecb commit dee9634

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

docs/resources/project_access_token.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ resource "gitlab_project_access_token" "example" {
1313
1414
scopes = [ "api" ]
1515
}
16+
17+
resource "gitlab_project_variable" "example" {
18+
project = gitlab_project.example.id
19+
key = "pat"
20+
value = gitlab_project_access_token.example.token
21+
}
1622
```
1723

1824
## Argument Reference

gitlab/resource_gitlab_project_access_token_test.go

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func TestAccGitlabProjectAccessToken_basic(t *testing.T) {
3232
}),
3333
),
3434
},
35-
// Update the pipeline trigger to change the parameters
35+
// Update the Project Access Token to change the parameters
3636
{
3737
Config: testAccGitlabProjectAccessTokenUpdateConfig(rInt),
3838
Check: resource.ComposeTestCheckFunc(
@@ -44,7 +44,20 @@ func TestAccGitlabProjectAccessToken_basic(t *testing.T) {
4444
}),
4545
),
4646
},
47-
// Update the pipeline trigger to get back to initial settings
47+
// Add a CICD variable with Project Access Token value
48+
{
49+
Config: testAccGitlabProjectAccessTokenUpdateConfigWithCICDvar(rInt),
50+
Check: resource.ComposeTestCheckFunc(
51+
testAccCheckGitlabProjectAccessTokenExists("gitlab_project_access_token.bar", &pat),
52+
testAccCheckGitlabProjectVariableExists(testAccProvider.Meta().(*gitlab.Client), "gitlab_project_variable.var"),
53+
testAccCheckGitlabProjectAccessTokenAttributes(&pat, &testAccGitlabProjectAccessTokenExpectedAttributes{
54+
name: "my new project token",
55+
scopes: map[string]bool{"read_repository": false, "api": true, "write_repository": false, "read_api": false},
56+
expiresAt: "2022-05-01",
57+
}),
58+
),
59+
},
60+
//Restore Project Access Token initial parameters
4861
{
4962
Config: testAccGitlabProjectAccessTokenConfig(rInt),
5063
Check: resource.ComposeTestCheckFunc(
@@ -202,3 +215,31 @@ resource "gitlab_project_access_token" "bar" {
202215
}
203216
`, rInt)
204217
}
218+
219+
func testAccGitlabProjectAccessTokenUpdateConfigWithCICDvar(rInt int) string {
220+
return fmt.Sprintf(`
221+
resource "gitlab_project" "foo" {
222+
name = "foo-%d"
223+
description = "Terraform acceptance tests"
224+
225+
# So that acceptance tests can be run in a gitlab organization
226+
# with no billing
227+
visibility_level = "public"
228+
}
229+
230+
resource "gitlab_project_access_token" "bar" {
231+
name = "my new project token"
232+
project = gitlab_project.foo.id
233+
expires_at = "2022-05-01"
234+
scopes = ["api"]
235+
}
236+
237+
238+
resource "gitlab_project_variable" "var" {
239+
project = gitlab_project.foo.id
240+
key = "my_proj_access_token"
241+
value = gitlab_project_access_token.bar.token
242+
}
243+
244+
`, rInt)
245+
}

0 commit comments

Comments
 (0)