Skip to content

Commit 9855758

Browse files
authored
Add CustomCIPath to resource gitlab_project (#662)
* Add CustomCIPath to resource `gitlab_project` * Delete acc test for simple GitLabProject attribute. - Amend existing Acceptance test to reflect this change in the default project
1 parent f3b926d commit 9855758

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

docs/resources/project.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ consult the [gitlab documentation](https://docs.gitlab.com/ee/user/project/repos
107107

108108
* `build_coverage_regex` - (Optional) Test coverage parsing for the project.
109109

110+
* `ci_config_path` - (Optional) Custom Path to CI config file.
111+
110112
## Attributes Reference
111113

112114
The following additional attributes are exported:

gitlab/resource_gitlab_project.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,10 @@ var resourceGitLabProjectSchema = map[string]*schema.Schema{
277277
Type: schema.TypeString,
278278
Optional: true,
279279
},
280+
"ci_config_path": {
281+
Type: schema.TypeString,
282+
Optional: true,
283+
},
280284
}
281285

282286
func resourceGitlabProject() *schema.Resource {
@@ -330,7 +334,7 @@ func resourceGitlabProjectSetToState(d *schema.ResourceData, project *gitlab.Pro
330334
d.Set("mirror_overwrites_diverged_branches", project.MirrorOverwritesDivergedBranches)
331335
d.Set("only_mirror_protected_branches", project.OnlyMirrorProtectedBranches)
332336
d.Set("build_coverage_regex", project.BuildCoverageRegex)
333-
337+
d.Set("ci_config_path", project.CIConfigPath)
334338
return nil
335339
}
336340

@@ -358,6 +362,7 @@ func resourceGitlabProjectCreate(d *schema.ResourceData, meta interface{}) error
358362
Mirror: gitlab.Bool(d.Get("mirror").(bool)),
359363
MirrorTriggerBuilds: gitlab.Bool(d.Get("mirror_trigger_builds").(bool)),
360364
BuildCoverageRegex: gitlab.String(d.Get("build_coverage_regex").(string)),
365+
CIConfigPath: gitlab.String(d.Get("ci_config_path").(string)),
361366
}
362367

363368
if v, ok := d.GetOk("path"); ok {
@@ -408,6 +413,10 @@ func resourceGitlabProjectCreate(d *schema.ResourceData, meta interface{}) error
408413
options.PagesAccessLevel = stringToAccessControlValue(v.(string))
409414
}
410415

416+
if v, ok := d.GetOk("ci_config_path"); ok {
417+
options.CIConfigPath = gitlab.String(v.(string))
418+
}
419+
411420
log.Printf("[DEBUG] create gitlab project %q", *options.Name)
412421

413422
project, _, err := client.Projects.CreateProject(options)
@@ -687,6 +696,10 @@ func resourceGitlabProjectUpdate(d *schema.ResourceData, meta interface{}) error
687696
options.BuildCoverageRegex = gitlab.String(d.Get("build_coverage_regex").(string))
688697
}
689698

699+
if d.HasChange("ci_config_path") {
700+
options.CIConfigPath = gitlab.String(d.Get("ci_config_path").(string))
701+
}
702+
690703
if *options != (gitlab.EditProjectOptions{}) {
691704
log.Printf("[DEBUG] update gitlab project %s", d.Id())
692705
_, _, err := client.Projects.EditProject(d.Id(), options)

gitlab/resource_gitlab_project_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ func TestAccGitlabProject_basic(t *testing.T) {
4848
PackagesEnabled: true,
4949
PagesAccessLevel: gitlab.PublicAccessControl,
5050
BuildCoverageRegex: "foo",
51+
CIConfigPath: ".gitlab-ci.yml@mynamespace/myproject",
5152
}
5253

5354
defaultsMainBranch = defaults
@@ -362,6 +363,7 @@ func TestAccGitlabProject_willError(t *testing.T) {
362363
PackagesEnabled: true,
363364
PagesAccessLevel: gitlab.PublicAccessControl,
364365
BuildCoverageRegex: "foo",
366+
CIConfigPath: ".gitlab-ci.yml@mynamespace/myproject",
365367
}
366368
willError := defaults
367369
willError.TagList = []string{"notatag"}
@@ -997,6 +999,7 @@ resource "gitlab_project" "foo" {
997999
only_allow_merge_if_all_discussions_are_resolved = true
9981000
pages_access_level = "public"
9991001
build_coverage_regex = "foo"
1002+
ci_config_path = ".gitlab-ci.yml@mynamespace/myproject"
10001003
}
10011004
`, rInt, rInt, defaultBranchStatement)
10021005
}

0 commit comments

Comments
 (0)