Skip to content

Commit 36c66a1

Browse files
authored
Merge pull request #1095 from timofurrer/gitlab-15.0
Support Gitlab 15.0
2 parents 98b059d + a64a4d7 commit 36c66a1

19 files changed

+313
-101
lines changed

.github/workflows/pr-acceptance-ce.yml

+6-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ on:
1212
- 'CHANGELOG.md'
1313
- 'CONTRIBUTING.md'
1414

15-
concurrency:
15+
concurrency:
1616
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
1717
cancel-in-progress: true
1818

@@ -31,6 +31,10 @@ jobs:
3131
timeout-minutes: 60
3232
runs-on: ubuntu-latest
3333
needs: [go-version]
34+
strategy:
35+
fail-fast: false
36+
matrix:
37+
gitlab-version: ["14.9.4-ce.0", "14.10.3-ce.0", "15.0.0-ce.0"]
3438
steps:
3539
- uses: actions/setup-go@v3
3640
with:
@@ -41,5 +45,5 @@ jobs:
4145
with:
4246
path: ~/go/pkg/mod
4347
key: ${{ github.job }}-${{ runner.os }}-go${{ env.GO_VERSION }}-${{ hashFiles('**/go.sum', 'GNUMakefile') }}
44-
- run: make testacc-up
48+
- run: make testacc-up GITLAB_CE_VERSION=${{ matrix.gitlab-version }}
4549
- run: make testacc

.github/workflows/pr-acceptance-ee.yml

+6-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ on:
2626
# Disable permissions on the GITHUB_TOKEN for all scopes.
2727
permissions: {}
2828

29-
concurrency:
29+
concurrency:
3030
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
3131
cancel-in-progress: true
3232

@@ -65,6 +65,10 @@ jobs:
6565
timeout-minutes: 60
6666
runs-on: ubuntu-latest
6767
needs: [go-version, license-encryption-password]
68+
strategy:
69+
fail-fast: false
70+
matrix:
71+
gitlab-version: ["14.9.4-ee.0", "14.10.3-ee.0", "15.0.0-ee.0"]
6872
steps:
6973
- uses: actions/setup-go@v3
7074
with:
@@ -79,7 +83,7 @@ jobs:
7983
run: |
8084
openssl version
8185
openssl enc -d -aes-256-cbc -pbkdf2 -iter 20000 -in Gitlab-license.encrypted -out Gitlab-license.txt -pass "pass:${{ secrets.LICENSE_ENCRYPTION_PASSWORD }}"
82-
- run: make testacc-up SERVICE=gitlab-ee
86+
- run: make testacc-up SERVICE=gitlab-ee GITLAB_EE_VERSION=${{ matrix.gitlab-version }}
8387
# Check out the pull request code (as opposed to the target project).
8488
# This overwrites the entire directory and deleted the unencrypted GitLab license file. The
8589
# service has already started and continues using the license even though the file is deleted.
@@ -96,4 +100,3 @@ jobs:
96100
# This is made safe because we have already cleaned up the unencrypted GitLab license file,
97101
# we have no other secrets, and we are not using GitHub tokens.
98102
- run: make testacc
99-

.github/workflows/push.yml

+10-2
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ jobs:
9494
timeout-minutes: 60
9595
runs-on: ubuntu-latest
9696
needs: [go-version]
97+
strategy:
98+
fail-fast: false
99+
matrix:
100+
gitlab-version: ["14.9.4-ce.0", "14.10.3-ce.0", "15.0.0-ce.0"]
97101
steps:
98102
- uses: actions/setup-go@v3
99103
with:
@@ -104,7 +108,7 @@ jobs:
104108
with:
105109
path: ~/go/pkg/mod
106110
key: ${{ github.job }}-${{ runner.os }}-go${{ env.GO_VERSION }}-${{ hashFiles('**/go.sum', 'GNUMakefile') }}
107-
- run: make testacc-up
111+
- run: make testacc-up GITLAB_CE_VERSION=${{ matrix.gitlab-version }}
108112
- run: make testacc
109113

110114
acceptance-ee:
@@ -114,6 +118,10 @@ jobs:
114118
timeout-minutes: 60
115119
runs-on: ubuntu-latest
116120
needs: [go-version, license-encryption-password]
121+
strategy:
122+
fail-fast: false
123+
matrix:
124+
gitlab-version: ["14.9.4-ee.0", "14.10.3-ee.0", "15.0.0-ee.0"]
117125
steps:
118126
- uses: actions/setup-go@v3
119127
with:
@@ -129,5 +137,5 @@ jobs:
129137
openssl version
130138
openssl enc -d -aes-256-cbc -pbkdf2 -iter 20000 -in Gitlab-license.encrypted -out Gitlab-license.txt -pass "pass:${{ secrets.LICENSE_ENCRYPTION_PASSWORD }}"
131139
# Note we specifically launch the gitlab-ee service.
132-
- run: make testacc-up SERVICE=gitlab-ee
140+
- run: make testacc-up SERVICE=gitlab-ee GITLAB_EE_VERSION=${{ matrix.gitlab-version }}
133141
- run: make testacc

CONTRIBUTING.md

+10
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ Your workspace will automatically open the repository and branch that you select
108108

109109
The acceptance tests can run against a Gitlab instance where you have a token with administrator permissions (likely not gitlab.com).
110110

111+
The GitHub Actions test against the three latest GitLab releases.
112+
111113
#### Option 1: Run tests against a local Gitlab container with docker-compose
112114

113115
This option is the easiest and requires [docker-compose](https://docs.docker.com/compose/install/) (version 1.13+) to be installed on your machine.
@@ -162,6 +164,14 @@ $ make testacc GITLAB_TOKEN=example123 GITLAB_BASE_URL=https://example.com/api/v
162164
$ make testacc-up SERVICE=gitlab-ee
163165
```
164166

167+
* **Run tests against specific GitLab version:**
168+
169+
Specify the GitLab release in the `GITLAB_CE_VERSION` or `GITLAB_EE_VERSION`, e.g.:
170+
171+
```sh
172+
$ make testacc-up GITLAB_CE_VERSION=15.0.0-ce.0
173+
```
174+
165175
* **Run a single test:**
166176

167177
You can pass a pattern to the `RUN` variable to run a reduced number of tests. For example:

docker-compose.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version: '3'
44
# Only one of these services should be run at a time.
55
services:
66
gitlab-ce:
7-
image: gitlab/gitlab-ce
7+
image: gitlab/gitlab-ce:${GITLAB_CE_VERSION:-latest}
88
restart: always
99
ports:
1010
- 8080:80
@@ -25,7 +25,7 @@ services:
2525
timeout: 2m
2626

2727
gitlab-ee:
28-
image: gitlab/gitlab-ee
28+
image: gitlab/gitlab-ee:${GITLAB_EE_VERSION:-latest}
2929
restart: always
3030
ports:
3131
- 8080:80

docs/resources/managed_license.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ resource "gitlab_managed_license" "mit" {
3737

3838
### Required
3939

40-
- `approval_status` (String) The approval status of the license. Valid values are: `approved`, `blacklisted`, `allowed`, `denied`. "approved" and "blacklisted"
41-
have been deprecated in favor of "allowed" and "denied"; use "allowed" and "denied" for GitLab versions 15.0 and higher.
40+
- `approval_status` (String) The approval status of the license. Valid values are: `approved`, `blacklisted`, `allowed`, `denied`. "approved" and "blacklisted"
41+
have been deprecated in favor of "allowed" and "denied"; use "allowed" and "denied" for GitLab versions 15.0 and higher.
4242
Prior to version 15.0 and after 14.6, the values are equivalent.
4343
- `name` (String) The name of the managed license (I.e., 'Apache License 2.0' or 'MIT license')
4444
- `project` (String) The ID of the project under which the managed license will be created.

docs/resources/topic.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ The `gitlab_topic` resource allows to manage the lifecycle of topics that are th
2323

2424
```terraform
2525
resource "gitlab_topic" "functional_programming" {
26-
name = "Functional Programming"
26+
name = "functional-programming"
27+
title = "Functional Programming"
2728
description = "In computer science, functional programming is a programming paradigm where programs are constructed by applying and composing functions."
2829
avatar = "${path.module}/avatar.png"
2930
avatar_hash = filesha256("${path.module}/avatar.png")
@@ -43,6 +44,7 @@ resource "gitlab_topic" "functional_programming" {
4344
- `avatar_hash` (String) The hash of the avatar image. Use `filesha256("path/to/avatar.png")` whenever possible. **Note**: this is used to trigger an update of the avatar. If it's not given, but an avatar is given, the avatar will be updated each time.
4445
- `description` (String) A text describing the topic.
4546
- `soft_destroy` (Boolean, Deprecated) Empty the topics fields instead of deleting it.
47+
- `title` (String) The topic's description. Requires at least GitLab 15.0 for which it's a required argument.
4648

4749
### Read-Only
4850

examples/resources/gitlab_topic/resource.tf

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
resource "gitlab_topic" "functional_programming" {
2-
name = "Functional Programming"
2+
name = "functional-programming"
3+
title = "Functional Programming"
34
description = "In computer science, functional programming is a programming paradigm where programs are constructed by applying and composing functions."
45
avatar = "${path.module}/avatar.png"
56
avatar_hash = filesha256("${path.module}/avatar.png")

internal/provider/data_source_gitlab_repository_file_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ resource "gitlab_repository_file" "foo" {
6666
branch = "main"
6767
content = base64encode("Meow goes the cat")
6868
commit_message = "feat: Meow"
69-
execute_filemode = true
7069
}
7170
7271
data "gitlab_repository_file" "foo" {

internal/provider/helper_test.go

+32-16
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package provider
55

66
import (
7+
"context"
78
"fmt"
89
"io"
910
"os"
@@ -67,22 +68,6 @@ func isRunningInCE() (bool, error) {
6768
return !isEE, err
6869
}
6970

70-
// orSkipFunc accepts many skipFunc and returns "true" if any returns true.
71-
func orSkipFunc(input ...SkipFunc) SkipFunc {
72-
return func() (bool, error) {
73-
for _, item := range input {
74-
result, err := item()
75-
if err != nil {
76-
return false, err
77-
}
78-
if result {
79-
return result, nil
80-
}
81-
}
82-
return false, nil
83-
}
84-
}
85-
8671
// testAccCheckEE is a test helper that skips the current test if the GitLab version is not GitLab Enterprise.
8772
// This is useful when the version needs to be checked during setup, before the Terraform acceptance test starts.
8873
func testAccCheckEE(t *testing.T) {
@@ -98,6 +83,37 @@ func testAccCheckEE(t *testing.T) {
9883
}
9984
}
10085

86+
func testAccRequiresLessThan(t *testing.T, requiredMaxVersion string) {
87+
isLessThan, err := isGitLabVersionLessThan(context.TODO(), testGitlabClient, requiredMaxVersion)()
88+
if err != nil {
89+
t.Fatalf("Failed to fetch GitLab version: %+v", err)
90+
}
91+
92+
if !isLessThan {
93+
t.Skipf("This test is only valid for GitLab versions less than %s", requiredMaxVersion)
94+
}
95+
}
96+
97+
func testAccRequiresAtLeast(t *testing.T, requiredMinVersion string) {
98+
isAtLeast, err := isGitLabVersionAtLeast(context.TODO(), testGitlabClient, requiredMinVersion)()
99+
if err != nil {
100+
t.Fatalf("Failed to fetch GitLab version: %+v", err)
101+
}
102+
103+
if !isAtLeast {
104+
t.Skipf("This test is only valid for GitLab versions newer than %s", requiredMinVersion)
105+
}
106+
}
107+
108+
func testAccIsRunningAtLeast(t *testing.T, requiredMinVersion string) bool {
109+
isAtLeast, err := isGitLabVersionAtLeast(context.TODO(), testGitlabClient, requiredMinVersion)()
110+
if err != nil {
111+
t.Fatalf("Failed to fetch GitLab version: %+v", err)
112+
}
113+
114+
return isAtLeast
115+
}
116+
101117
// testAccCurrentUser is a test helper for getting the current user of the provided client.
102118
func testAccCurrentUser(t *testing.T) *gitlab.User {
103119
t.Helper()

internal/provider/resource_gitlab_group_cluster_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ func TestAccGitlabGroupCluster_basic(t *testing.T) {
1818
rInt := acctest.RandInt()
1919

2020
resource.Test(t, resource.TestCase{
21+
PreCheck: func() { testAccRequiresLessThan(t, "15.0") },
2122
ProviderFactories: providerFactories,
2223
CheckDestroy: testAccCheckGitlabGroupClusterDestroy,
2324
Steps: []resource.TestStep{
@@ -105,6 +106,7 @@ func TestAccGitlabGroupCluster_import(t *testing.T) {
105106
rInt := acctest.RandInt()
106107

107108
resource.Test(t, resource.TestCase{
109+
PreCheck: func() { testAccRequiresLessThan(t, "15.0") },
108110
ProviderFactories: providerFactories,
109111
CheckDestroy: testAccCheckGitlabGroupClusterDestroy,
110112
Steps: []resource.TestStep{

internal/provider/resource_gitlab_instance_cluster_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ func TestAccGitlabInstanceCluster_basic(t *testing.T) {
1919
rInt := acctest.RandInt()
2020

2121
resource.Test(t, resource.TestCase{
22+
PreCheck: func() { testAccRequiresLessThan(t, "15.0") },
2223
ProviderFactories: providerFactories,
2324
CheckDestroy: testAccCheckGitlabInstanceClusterDestroy,
2425
Steps: []resource.TestStep{
@@ -107,6 +108,7 @@ func TestAccGitlabInstanceCluster_import(t *testing.T) {
107108
rInt := acctest.RandInt()
108109

109110
resource.Test(t, resource.TestCase{
111+
PreCheck: func() { testAccRequiresLessThan(t, "15.0") },
110112
ProviderFactories: providerFactories,
111113
CheckDestroy: testAccCheckGitlabInstanceClusterDestroy,
112114
Steps: []resource.TestStep{

internal/provider/resource_gitlab_managed_license.go

+37-21
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ var _ = registerResource("gitlab_managed_license", func() *schema.Resource {
5353
ForceNew: false,
5454
ValidateFunc: validation.StringInSlice(managedLicenseAllowedValues, true),
5555
DiffSuppressFunc: checkDeprecatedValuesForDiff,
56-
Description: fmt.Sprintf(`The approval status of the license. Valid values are: %s. "approved" and "blacklisted"
57-
have been deprecated in favor of "allowed" and "denied"; use "allowed" and "denied" for GitLab versions 15.0 and higher.
56+
Description: fmt.Sprintf(`The approval status of the license. Valid values are: %s. "approved" and "blacklisted"
57+
have been deprecated in favor of "allowed" and "denied"; use "allowed" and "denied" for GitLab versions 15.0 and higher.
5858
Prior to version 15.0 and after 14.6, the values are equivalent.`, renderValueListForDocs(managedLicenseAllowedValues)),
5959
},
6060
},
@@ -65,9 +65,14 @@ func resourceGitlabManagedLicenseCreate(ctx context.Context, d *schema.ResourceD
6565
client := meta.(*gitlab.Client)
6666
project := d.Get("project").(string)
6767

68+
approvalStatus, err := stringToApprovalStatus(ctx, client, d.Get("approval_status").(string))
69+
if err != nil {
70+
return diag.FromErr(err)
71+
}
72+
6873
options := &gitlab.AddManagedLicenseOptions{
6974
Name: gitlab.String(d.Get("name").(string)),
70-
ApprovalStatus: stringToApprovalStatus(d.Get("approval_status").(string)),
75+
ApprovalStatus: approvalStatus,
7176
}
7277

7378
log.Printf("[DEBUG] create gitlab Managed License on Project %s, with Name %s", project, *options.Name)
@@ -131,12 +136,13 @@ func resourceGitlabManagedLicenseUpdate(ctx context.Context, d *schema.ResourceD
131136
return diag.FromErr(err)
132137
}
133138

134-
opts := &gitlab.EditManagedLicenceOptions{
135-
ApprovalStatus: stringToApprovalStatus(d.Get("approval_status").(string)),
139+
approvalStatus, err := stringToApprovalStatus(ctx, client, d.Get("approval_status").(string))
140+
if err != nil {
141+
return diag.FromErr(err)
136142
}
137143

138-
if d.HasChange("approval_status") {
139-
opts.ApprovalStatus = stringToApprovalStatus(d.Get("approval_status").(string))
144+
opts := &gitlab.EditManagedLicenceOptions{
145+
ApprovalStatus: approvalStatus,
140146
}
141147

142148
log.Printf("[DEBUG] update gitlab Managed License %s", d.Id())
@@ -152,22 +158,32 @@ func resourceGitlabManagedLicenseUpdate(ctx context.Context, d *schema.ResourceD
152158
}
153159

154160
// Convert the incoming string into the proper constant value for passing into the API.
155-
func stringToApprovalStatus(s string) *gitlab.LicenseApprovalStatusValue {
156-
lookup := map[string]gitlab.LicenseApprovalStatusValue{
157-
"approved": gitlab.LicenseApproved,
158-
"blacklisted": gitlab.LicenseBlacklisted,
159-
160-
// This is counter-intuitive, but currently the API response from the non-deprecated
161-
// values is the deprecated values. So we have to map them here.
162-
"allowed": gitlab.LicenseApproved,
163-
"denied": gitlab.LicenseBlacklisted,
164-
}
161+
func stringToApprovalStatus(ctx context.Context, client *gitlab.Client, s string) (*gitlab.LicenseApprovalStatusValue, error) {
162+
var value gitlab.LicenseApprovalStatusValue
163+
notSupported, err := isGitLabVersionAtLeast(ctx, client, "15.0")()
164+
if err != nil {
165+
return nil, fmt.Errorf("failed to fetch GitLab version: %+v", err)
166+
}
167+
if notSupported {
168+
value = gitlab.LicenseApprovalStatusValue(s)
169+
} else {
170+
lookup := map[string]gitlab.LicenseApprovalStatusValue{
171+
"approved": gitlab.LicenseApproved,
172+
"blacklisted": gitlab.LicenseBlacklisted,
173+
174+
// This is counter-intuitive, but currently the API response from the non-deprecated
175+
// values is the deprecated values. So we have to map them here.
176+
"allowed": gitlab.LicenseApproved,
177+
"denied": gitlab.LicenseBlacklisted,
178+
}
165179

166-
value, ok := lookup[s]
167-
if !ok {
168-
return nil
180+
v, ok := lookup[s]
181+
if !ok {
182+
return nil, fmt.Errorf("invalid approval status value %q", s)
183+
}
184+
value = v
169185
}
170-
return &value
186+
return &value, nil
171187
}
172188

173189
func projectIdAndLicenseIdFromId(id string) (string, int, error) {

0 commit comments

Comments
 (0)