Skip to content

Commit da9cca3

Browse files
authored
Merge pull request #291 from terraform-providers/soft-delete
Support for Gitlab EE soft-delete of groups and projects
2 parents d0cbbce + 49b79d4 commit da9cca3

36 files changed

+603
-153
lines changed

.github/workflows/acceptance-tests.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
- name: Set up Go
1010
uses: actions/setup-go@v1
1111
with:
12-
go-version: 1.12
12+
go-version: 1.14
1313
id: go
1414

1515
- name: Check out code repository source code
@@ -36,7 +36,7 @@ jobs:
3636
- name: Set up Go
3737
uses: actions/setup-go@v1
3838
with:
39-
go-version: 1.12
39+
go-version: 1.14
4040
id: go
4141

4242
- name: Check out code repository source code
@@ -59,6 +59,7 @@ jobs:
5959
echo "::set-env name=GO111MODULE::on"
6060
echo "::set-env name=GITLAB_TOKEN::20char-testing-token"
6161
echo "::set-env name=GITLAB_BASE_URL::http://127.0.0.1:8080/api/v4"
62+
echo "::set-env name=TF_LOG::DEBUG"
6263
6364
- name: Start Gitlab and run acceptance tests
6465
run: |

.github/workflows/unit-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
strategy:
88
fail-fast: false
99
matrix:
10-
go: [1.12, 1.13, 1.14]
10+
go: [1.13, 1.14]
1111
os: [ubuntu-latest, macos-latest, windows-latest]
1212
make_target: [test, vet]
1313

.github/workflows/website.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
- name: Set up Go
1010
uses: actions/setup-go@v1
1111
with:
12-
go-version: 1.12
12+
go-version: 1.14
1313
id: go
1414

1515
# https://help.github.com/en/actions/reference/workflow-commands-for-github-actions

.travis.yml

Lines changed: 0 additions & 30 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
## 2.5.1 (Unreleased)
2+
3+
BUGFIXES:
4+
* Support for soft-delete of groups and projects in Gitlab Enterprise Edition ([GH-282][GH-283][GH-285][GH-291])
5+
6+
ENHANCEMENTS:
7+
* Switched from Travis CI to Github Actions ([GH-216])
8+
29
## 2.5.0 (December 05, 2019)
310

411
ENHANCEMENTS:

GNUmakefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
TEST?=$$(go list ./... |grep -v 'vendor')
1+
TEST?=./gitlab
22
GOFMT_FILES?=$$(find . -name '*.go' |grep -v vendor)
33
WEBSITE_REPO=github.com/hashicorp/terraform-website
44
PKG_NAME=gitlab
@@ -14,7 +14,7 @@ test: fmtcheck
1414
xargs -t -n4 go test $(TESTARGS) -timeout=30s -parallel=4
1515

1616
testacc: fmtcheck
17-
TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout 120m
17+
TF_ACC=1 go test -v $(TEST) $(TESTARGS) -timeout 40m
1818

1919
vet:
2020
@echo "go vet ."

gitlab/resource_gitlab_group.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"log"
66
"net/http"
7+
"strings"
78
"time"
89

910
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
@@ -127,6 +128,11 @@ func resourceGitlabGroupRead(d *schema.ResourceData, meta interface{}) error {
127128
}
128129
return err
129130
}
131+
if group.MarkedForDeletionOn != nil {
132+
log.Printf("[DEBUG] gitlab group %s is marked for deletion", d.Id())
133+
d.SetId("")
134+
return nil
135+
}
130136

131137
d.SetId(fmt.Sprintf("%d", group.ID))
132138
d.Set("name", group.Name)
@@ -190,7 +196,7 @@ func resourceGitlabGroupDelete(d *schema.ResourceData, meta interface{}) error {
190196
log.Printf("[DEBUG] Delete gitlab group %s", d.Id())
191197

192198
_, err := client.Groups.DeleteGroup(d.Id())
193-
if err != nil {
199+
if err != nil && !strings.Contains(err.Error(), "Group has been already marked for deletion") {
194200
return fmt.Errorf("error deleting group %s: %s", d.Id(), err)
195201
}
196202

@@ -208,6 +214,10 @@ func resourceGitlabGroupDelete(d *schema.ResourceData, meta interface{}) error {
208214
log.Printf("[ERROR] Received error: %#v", err)
209215
return out, "Error", err
210216
}
217+
if out.MarkedForDeletionOn != nil {
218+
// Represents a Gitlab EE soft-delete
219+
return out, "Deleted", nil
220+
}
211221
return out, "Deleting", nil
212222
},
213223

gitlab/resource_gitlab_group_label_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@ func testAccCheckGitlabGroupLabelDestroy(s *terraform.State) error {
119119
group, resp, err := conn.Groups.GetGroup(rs.Primary.ID)
120120
if err == nil {
121121
if group != nil && fmt.Sprintf("%d", group.ID) == rs.Primary.ID {
122-
return fmt.Errorf("Group still exists")
122+
if group.MarkedForDeletionOn == nil {
123+
return fmt.Errorf("Group still exists")
124+
}
123125
}
124126
}
125127
if resp.StatusCode != 404 {

gitlab/resource_gitlab_group_test.go

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -137,21 +137,22 @@ func TestAccGitlabGroup_nested(t *testing.T) {
137137
}),
138138
),
139139
},
140-
{
141-
Config: testAccGitlabNestedGroupConfig(rInt),
142-
Check: resource.ComposeTestCheckFunc(
143-
testAccCheckGitlabGroupExists("gitlab_group.foo", &group),
144-
testAccCheckGitlabGroupExists("gitlab_group.foo2", &group2),
145-
testAccCheckGitlabGroupExists("gitlab_group.nested_foo", &nestedGroup),
146-
testAccCheckGitlabGroupAttributes(&nestedGroup, &testAccGitlabGroupExpectedAttributes{
147-
Name: fmt.Sprintf("nfoo-name-%d", rInt),
148-
Path: fmt.Sprintf("nfoo-path-%d", rInt),
149-
Description: "Terraform acceptance tests",
150-
LFSEnabled: true,
151-
Parent: &group,
152-
}),
153-
),
154-
},
140+
// TODO In EE version, re-creating on the same path where a previous group was soft-deleted doesn't work.
141+
// {
142+
// Config: testAccGitlabNestedGroupConfig(rInt),
143+
// Check: resource.ComposeTestCheckFunc(
144+
// testAccCheckGitlabGroupExists("gitlab_group.foo", &group),
145+
// testAccCheckGitlabGroupExists("gitlab_group.foo2", &group2),
146+
// testAccCheckGitlabGroupExists("gitlab_group.nested_foo", &nestedGroup),
147+
// testAccCheckGitlabGroupAttributes(&nestedGroup, &testAccGitlabGroupExpectedAttributes{
148+
// Name: fmt.Sprintf("nfoo-name-%d", rInt),
149+
// Path: fmt.Sprintf("nfoo-path-%d", rInt),
150+
// Description: "Terraform acceptance tests",
151+
// LFSEnabled: true,
152+
// Parent: &group,
153+
// }),
154+
// ),
155+
// },
155156
},
156157
})
157158
}
@@ -264,7 +265,9 @@ func testAccCheckGitlabGroupDestroy(s *terraform.State) error {
264265
group, resp, err := conn.Groups.GetGroup(rs.Primary.ID)
265266
if err == nil {
266267
if group != nil && fmt.Sprintf("%d", group.ID) == rs.Primary.ID {
267-
return fmt.Errorf("Group still exists")
268+
if group.MarkedForDeletionOn == nil {
269+
return fmt.Errorf("Group still exists")
270+
}
268271
}
269272
}
270273
if resp.StatusCode != 404 {

gitlab/resource_gitlab_group_variable_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@ func testAccCheckGitlabGroupVariableDestroy(s *terraform.State) error {
119119
_, resp, err := conn.Groups.GetGroup(rs.Primary.ID)
120120
if err == nil {
121121
//if gotRepo != nil && fmt.Sprintf("%d", gotRepo.ID) == rs.Primary.ID {
122-
// return fmt.Errorf("Repository still exists")
122+
// if gotRepo.MarkedForDeletionAt == nil {
123+
// return fmt.Errorf("Repository still exists")
124+
// }
123125
//}
124126
}
125127
if resp.StatusCode != 404 {

0 commit comments

Comments
 (0)