Skip to content

Commit cf82021

Browse files
authored
Allow disable/enable packages repository (#405)
* Bump go-gitlab to v.0.38.1 * feat: allow to enable/disable packages repository Closes: #404
1 parent b125af0 commit cf82021

30 files changed

+845
-187
lines changed

docs/data-sources/project.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,6 @@ The following attributes are exported:
6969

7070
* `archived` - Whether the project is in read-only mode (archived).
7171

72-
* `remove_source_branch_after_merge` - Enable `Delete source branch` option by default for all new merge requests
72+
* `remove_source_branch_after_merge` - Enable `Delete source branch` option by default for all new merge requests
73+
74+
* `packages_enabled` - Enable packages repository for the project.

docs/resources/project.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ The following arguments are supported:
7878

7979
* `initialize_with_readme` - (Optional) Create master branch with first commit containing a README.md file.
8080

81+
* `packages_enabled` - (Optional) Enable packages repository for the project.
82+
8183
## Attributes Reference
8284

8385
The following additional attributes are exported:

gitlab/data_source_gitlab_projects.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ func flattenProjects(projects []*gitlab.Project) (values []map[string]interface{
156156
"_links": flattenProjectLinks(project.Links),
157157
"ci_config_path": project.CIConfigPath,
158158
"custom_attributes": project.CustomAttributes,
159+
"packages_enabled": project.PackagesEnabled,
159160
}
160161
values = append(values, v)
161162
}
@@ -648,6 +649,10 @@ func dataSourceGitlabProjects() *schema.Resource {
648649
Type: schema.TypeMap,
649650
},
650651
},
652+
"packages_enabled": {
653+
Type: schema.TypeBool,
654+
Computed: true,
655+
},
651656
},
652657
},
653658
},

gitlab/resource_gitlab_project.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,11 @@ var resourceGitLabProjectSchema = map[string]*schema.Schema{
186186
Type: schema.TypeBool,
187187
Optional: true,
188188
},
189+
"packages_enabled": {
190+
Type: schema.TypeBool,
191+
Optional: true,
192+
Default: true,
193+
},
189194
}
190195

191196
func resourceGitlabProject() *schema.Resource {
@@ -230,6 +235,7 @@ func resourceGitlabProjectSetToState(d *schema.ResourceData, project *gitlab.Pro
230235
d.Set("tags", project.TagList)
231236
d.Set("archived", project.Archived)
232237
d.Set("remove_source_branch_after_merge", project.RemoveSourceBranchAfterMerge)
238+
d.Set("packages_enabled", project.PackagesEnabled)
233239
}
234240

235241
func resourceGitlabProjectCreate(d *schema.ResourceData, meta interface{}) error {
@@ -252,6 +258,7 @@ func resourceGitlabProjectCreate(d *schema.ResourceData, meta interface{}) error
252258
OnlyAllowMergeIfAllDiscussionsAreResolved: gitlab.Bool(d.Get("only_allow_merge_if_all_discussions_are_resolved").(bool)),
253259
SharedRunnersEnabled: gitlab.Bool(d.Get("shared_runners_enabled").(bool)),
254260
RemoveSourceBranchAfterMerge: gitlab.Bool(d.Get("remove_source_branch_after_merge").(bool)),
261+
PackagesEnabled: gitlab.Bool(d.Get("packages_enabled").(bool)),
255262
}
256263

257264
if v, ok := d.GetOk("path"); ok {
@@ -429,6 +436,10 @@ func resourceGitlabProjectUpdate(d *schema.ResourceData, meta interface{}) error
429436
options.RemoveSourceBranchAfterMerge = gitlab.Bool(d.Get("remove_source_branch_after_merge").(bool))
430437
}
431438

439+
if d.HasChange("packages_enabled") {
440+
options.PackagesEnabled = gitlab.Bool(d.Get("packages_enabled").(bool))
441+
}
442+
432443
if *options != (gitlab.EditProjectOptions{}) {
433444
log.Printf("[DEBUG] update gitlab project %s", d.Id())
434445
_, _, err := client.Projects.EditProject(d.Id(), options)

gitlab/resource_gitlab_project_test.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ func TestAccGitlabProject_basic(t *testing.T) {
4040
MergeMethod: gitlab.FastForwardMerge,
4141
OnlyAllowMergeIfPipelineSucceeds: true,
4242
OnlyAllowMergeIfAllDiscussionsAreResolved: true,
43-
Archived: false, // needless, but let's make this explicit
43+
Archived: false, // needless, but let's make this explicit
44+
PackagesEnabled: true,
4445
}
4546

4647
defaultsMasterBranch = defaults
@@ -80,7 +81,8 @@ func TestAccGitlabProject_basic(t *testing.T) {
8081
MergeMethod: gitlab.FastForwardMerge,
8182
OnlyAllowMergeIfPipelineSucceeds: true,
8283
OnlyAllowMergeIfAllDiscussionsAreResolved: true,
83-
Archived: true,
84+
Archived: true,
85+
PackagesEnabled: false,
8486
}, &received),
8587
),
8688
},
@@ -151,6 +153,7 @@ func TestAccGitlabProject_willError(t *testing.T) {
151153
MergeMethod: gitlab.FastForwardMerge,
152154
OnlyAllowMergeIfPipelineSucceeds: true,
153155
OnlyAllowMergeIfAllDiscussionsAreResolved: true,
156+
PackagesEnabled: true,
154157
}
155158
willError := defaults
156159
willError.TagList = []string{"notatag"}
@@ -249,6 +252,7 @@ func TestAccGitlabProject_transfer(t *testing.T) {
249252
MergeMethod: gitlab.NoFastForwardMerge,
250253
OnlyAllowMergeIfPipelineSucceeds: false,
251254
OnlyAllowMergeIfAllDiscussionsAreResolved: false,
255+
PackagesEnabled: true,
252256
}
253257

254258
resource.Test(t, resource.TestCase{
@@ -534,8 +538,9 @@ resource "gitlab_project" "foo" {
534538
snippets_enabled = false
535539
container_registry_enabled = false
536540
lfs_enabled = false
537-
shared_runners_enabled = false
538-
archived = true
541+
shared_runners_enabled = false
542+
archived = true
543+
packages_enabled = false
539544
}
540545
`, rInt, rInt)
541546
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/gitlabhq/terraform-provider-gitlab
33
require (
44
github.com/hashicorp/terraform-plugin-sdk v1.13.1
55
github.com/mitchellh/hashstructure v1.0.0
6-
github.com/xanzy/go-gitlab v0.34.1
6+
github.com/xanzy/go-gitlab v0.38.1
77
)
88

99
go 1.14

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ github.com/ulikunitz/xz v0.5.5/go.mod h1:2bypXElzHzzJZwzH67Y6wb67pO62Rzfn7BSiF4A
192192
github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
193193
github.com/vmihailenco/msgpack v4.0.1+incompatible h1:RMF1enSPeKTlXrXdOcqjFUElywVZjjC6pqse21bKbEU=
194194
github.com/vmihailenco/msgpack v4.0.1+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
195-
github.com/xanzy/go-gitlab v0.34.1 h1:Dtqla2gWIQIevfZVS6FY4qjgrKf+5LYLzW6XBNstGSw=
196-
github.com/xanzy/go-gitlab v0.34.1/go.mod h1:sPLojNBn68fMUWSxIJtdVVIP8uSBYqesTfDUseX11Ug=
195+
github.com/xanzy/go-gitlab v0.38.1 h1:st5/Ag4h8CqVfp3LpOWW0Jd4jYHTGETwu0KksYDPnYE=
196+
github.com/xanzy/go-gitlab v0.38.1/go.mod h1:sPLojNBn68fMUWSxIJtdVVIP8uSBYqesTfDUseX11Ug=
197197
github.com/zclconf/go-cty v1.0.0/go.mod h1:xnAOWiHeOqg2nWS62VtQ7pbOu17FtxJNW8RLEih+O3s=
198198
github.com/zclconf/go-cty v1.1.0/go.mod h1:xnAOWiHeOqg2nWS62VtQ7pbOu17FtxJNW8RLEih+O3s=
199199
github.com/zclconf/go-cty v1.2.1 h1:vGMsygfmeCl4Xb6OA5U5XVAaQZ69FvoG7X2jUtQujb8=

vendor/github.com/xanzy/go-gitlab/client_options.go

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/xanzy/go-gitlab/commits.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/xanzy/go-gitlab/epics.go

Lines changed: 49 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)