Skip to content

Commit 6f79ff8

Browse files
committed
First review
1 parent c93ad65 commit 6f79ff8

10 files changed

+80
-170
lines changed

docs/data-sources/project_milestone.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ data "gitlab_project_milestone" "example" {
3434

3535
### Required
3636

37-
- `milestone_id` (Number) The global ID of the project’s milestone.
37+
- `milestone_id` (Number) The instance-wide ID of the project’s milestone.
3838
- `project_id` (String) The ID or URL-encoded path of the project owned by the authenticated user.
3939

4040
### Optional
@@ -47,7 +47,7 @@ data "gitlab_project_milestone" "example" {
4747
- `description` (String) The description of the milestone.
4848
- `due_date` (String) The due date of the milestone. Date time string in the format YYYY-MM-DD, for example 2016-03-11.
4949
- `expired` (Boolean) Bool, true if milestore expired.
50-
- `iid` (Number) The ID of the milestone only in one project.
50+
- `iid` (Number) The ID of the project's milestone.
5151
- `start_date` (String) The start date of the milestone. Date time string in the format YYYY-MM-DD, for example 2016-03-11.
5252
- `state` (String) The state of the milestone. Valid values are: `active`, `closed`.
5353
- `title` (String) The title of a milestone.

docs/resources/project_milestone.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
page_title: "gitlab_project_milestone Resource - terraform-provider-gitlab"
44
subcategory: ""
55
description: |-
6-
The gitlab_project_milestone resource allows to manage the lifecycle of a milestone (project).
6+
The gitlab_project_milestone resource allows to manage the lifecycle of a project milestone.
77
Upstream API: GitLab REST API docs https://docs.gitlab.com/ee/api/milestones.html
88
---
99

1010
# gitlab_project_milestone (Resource)
1111

12-
The `gitlab_project_milestone` resource allows to manage the lifecycle of a milestone (project).
12+
The `gitlab_project_milestone` resource allows to manage the lifecycle of a project milestone.
1313

1414
**Upstream API**: [GitLab REST API docs](https://docs.gitlab.com/ee/api/milestones.html)
1515

@@ -50,8 +50,8 @@ resource "gitlab_project_milestone" "example" {
5050
### Read-Only
5151

5252
- `expired` (Boolean) Bool, true if milestore expired.
53-
- `iid` (Number) The ID of the milestone only in one project.
54-
- `milestone_id` (Number) The global ID of the project’s milestone.
53+
- `iid` (Number) The ID of the project's milestone.
54+
- `milestone_id` (Number) The instance-wide ID of the project’s milestone.
5555
- `web_url` (String) The web URL of the milestone.
5656

5757
## Import

internal/provider/data_source_gitlab_project_milestone.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func dataSourceGitlabProjectMilestoneRead(ctx context.Context, d *schema.Resourc
2828
if err != nil {
2929
return diag.FromErr(err)
3030
}
31-
d.SetId(buildTwoPartIDInterface(project, milestoneID))
31+
d.SetId(resourceGitLabProjectMilestoneBuildId(project, milestoneID))
3232
stateMap := gitlabProjectMilestoneToStateMap(milestone)
3333

3434
if err := setStateMapInResourceData(stateMap, d); err != nil {

internal/provider/data_source_gitlab_project_milestone_test.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ func TestAccDataSourceGitlabProjectMilestone_basic(t *testing.T) {
1818
ProviderFactories: providerFactories,
1919
Steps: []resource.TestStep{
2020
{
21-
Config: testAccDataGitlabProjectMilestoneConfig(testProject.ID, testMilestone.ID),
21+
Config: fmt.Sprintf(`
22+
data "gitlab_project_milestone" "this" {
23+
project_id = "%d"
24+
milestone_id = "%d"
25+
}`, testProject.ID, testMilestone.ID),
2226
Check: resource.ComposeTestCheckFunc(
2327
resource.TestCheckResourceAttr("data.gitlab_project_milestone.this", "milestone_id", fmt.Sprintf("%v", testMilestone.ID)),
2428
resource.TestCheckResourceAttr("data.gitlab_project_milestone.this", "title", testMilestone.Title),
@@ -28,12 +32,3 @@ func TestAccDataSourceGitlabProjectMilestone_basic(t *testing.T) {
2832
},
2933
})
3034
}
31-
32-
func testAccDataGitlabProjectMilestoneConfig(projectID int, milestoneID int) string {
33-
return fmt.Sprintf(`
34-
data "gitlab_project_milestone" "this" {
35-
project_id = "%d"
36-
milestone_id = "%d"
37-
}
38-
`, projectID, milestoneID)
39-
}

internal/provider/data_source_gitlab_project_milestones.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package provider
22

33
import (
44
"context"
5+
"fmt"
56
"log"
67

78
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
@@ -113,7 +114,7 @@ func dataSourceGitlabProjectMilestonesRead(ctx context.Context, d *schema.Resour
113114
}
114115

115116
log.Printf("[DEBUG] get gitlab milestones from project: %s", project)
116-
d.SetId(buildTwoPartIDInterface(project, optionsHash))
117+
d.SetId(fmt.Sprintf("%s:%d", project, optionsHash))
117118
if err = d.Set("milestones", flattenGitlabProjectMilestones(milestones)); err != nil {
118119
return diag.Errorf("Failed to set milestones to state: %v", err)
119120
}

internal/provider/data_source_gitlab_project_milestones_test.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ func TestAccDataGitlabProjectMilestones_basic(t *testing.T) {
1818
ProviderFactories: providerFactories,
1919
Steps: []resource.TestStep{
2020
{
21-
Config: testAccDataGitlabProjectMilestonesConfig(testProject.ID),
21+
Config: fmt.Sprintf(`
22+
data "gitlab_project_milestones" "this" {
23+
project_id = "%d"
24+
}`, testProject.ID),
2225
Check: resource.ComposeTestCheckFunc(
2326
resource.TestCheckResourceAttr("data.gitlab_project_milestones.this", "milestones.#", fmt.Sprintf("%d", len(testMilestones))),
2427
resource.TestCheckResourceAttr("data.gitlab_project_milestones.this", "milestones.0.title", testMilestones[1].Title),
@@ -30,11 +33,3 @@ func TestAccDataGitlabProjectMilestones_basic(t *testing.T) {
3033
},
3134
})
3235
}
33-
34-
func testAccDataGitlabProjectMilestonesConfig(projectID int) string {
35-
return fmt.Sprintf(`
36-
data "gitlab_project_milestones" "this" {
37-
project_id = "%d"
38-
}
39-
`, projectID)
40-
}

internal/provider/resource_gitlab_project_milestone.go

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package provider
22

33
import (
44
"context"
5+
"fmt"
56
"log"
7+
"strconv"
68

79
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
810
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@@ -16,7 +18,7 @@ var milestoneStateToStateEvent = map[string]string{
1618

1719
var _ = registerResource("gitlab_project_milestone", func() *schema.Resource {
1820
return &schema.Resource{
19-
Description: `The ` + "`gitlab_project_milestone`" + ` resource allows to manage the lifecycle of a milestone (project).
21+
Description: `The ` + "`gitlab_project_milestone`" + ` resource allows to manage the lifecycle of a project milestone.
2022
2123
**Upstream API**: [GitLab REST API docs](https://docs.gitlab.com/ee/api/milestones.html)`,
2224

@@ -27,9 +29,7 @@ var _ = registerResource("gitlab_project_milestone", func() *schema.Resource {
2729
Importer: &schema.ResourceImporter{
2830
StateContext: schema.ImportStatePassthroughContext,
2931
},
30-
Schema: constructSchema(
31-
gitlabProjectMilestoneGetSchema(),
32-
),
32+
Schema: gitlabProjectMilestoneGetSchema(),
3333
}
3434
})
3535

@@ -65,7 +65,7 @@ func resourceGitlabProjectMilestoneCreate(ctx context.Context, d *schema.Resourc
6565
log.Printf("[WARN] failed to create gitlab milestone in project %s with title %s (response %v)", project, title, resp)
6666
return diag.FromErr(err)
6767
}
68-
d.SetId(buildTwoPartIDInterface(project, milestone.ID))
68+
d.SetId(resourceGitLabProjectMilestoneBuildId(project, milestone.ID))
6969

7070
updateOptions := gitlab.UpdateMilestoneOptions{}
7171
if stateEvent, ok := d.GetOk("state"); ok {
@@ -83,7 +83,7 @@ func resourceGitlabProjectMilestoneCreate(ctx context.Context, d *schema.Resourc
8383

8484
func resourceGitlabProjectMilestoneRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
8585
client := meta.(*gitlab.Client)
86-
project, milestoneID, err := parseTwoPartIDInt(d.Id())
86+
project, milestoneID, err := resourceGitLabProjectMilestoneParseId(d.Id())
8787
if err != nil {
8888
return diag.FromErr(err)
8989
}
@@ -109,7 +109,7 @@ func resourceGitlabProjectMilestoneRead(ctx context.Context, d *schema.ResourceD
109109

110110
func resourceGitlabProjectMilestoneUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
111111
client := meta.(*gitlab.Client)
112-
project, milestoneID, err := parseTwoPartIDInt(d.Id())
112+
project, milestoneID, err := resourceGitLabProjectMilestoneParseId(d.Id())
113113
if err != nil {
114114
return diag.FromErr(err)
115115
}
@@ -153,7 +153,7 @@ func resourceGitlabProjectMilestoneUpdate(ctx context.Context, d *schema.Resourc
153153

154154
func resourceGitlabProjectMilestoneDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
155155
client := meta.(*gitlab.Client)
156-
project, milestoneID, err := parseTwoPartIDInt(d.Id())
156+
project, milestoneID, err := resourceGitLabProjectMilestoneParseId(d.Id())
157157
if err != nil {
158158
return diag.FromErr(err)
159159
}
@@ -166,3 +166,22 @@ func resourceGitlabProjectMilestoneDelete(ctx context.Context, d *schema.Resourc
166166
}
167167
return nil
168168
}
169+
170+
func resourceGitLabProjectMilestoneParseId(id string) (string, int, error) {
171+
project, milestone, err := parseTwoPartID(id)
172+
if err != nil {
173+
return "", 0, err
174+
}
175+
176+
milestoneID, err := strconv.Atoi(milestone)
177+
if err != nil {
178+
return "", 0, err
179+
}
180+
181+
return project, milestoneID, nil
182+
}
183+
184+
func resourceGitLabProjectMilestoneBuildId(project string, milestoneID int) string {
185+
stringMilestoneID := fmt.Sprintf("%d", milestoneID)
186+
return buildTwoPartID(&project, &stringMilestoneID)
187+
}

0 commit comments

Comments
 (0)