Skip to content

Commit 0ca8c61

Browse files
authored
Merge pull request #1044 from Moon1706/main
Added gitlab_project_milestone as a resource and data source
2 parents ea3e3e2 + 5695395 commit 0ca8c61

16 files changed

+890
-12
lines changed
+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "gitlab_project_milestone Data Source - terraform-provider-gitlab"
4+
subcategory: ""
5+
description: |-
6+
The gitlab_project_milestone data source allows get details of a project milestone.
7+
Upstream API: GitLab REST API docs https://docs.gitlab.com/ee/api/milestones.html
8+
---
9+
10+
# gitlab_project_milestone (Data Source)
11+
12+
The `gitlab_project_milestone` data source allows get details of a project milestone.
13+
14+
**Upstream API**: [GitLab REST API docs](https://docs.gitlab.com/ee/api/milestones.html)
15+
16+
## Example Usage
17+
18+
```terraform
19+
# By project ID
20+
data "gitlab_project_milestone" "example" {
21+
project = "12345"
22+
milestone_id = 10
23+
}
24+
25+
# By project full path
26+
data "gitlab_project_milestone" "example" {
27+
project = "foo/bar"
28+
milestone_id = 10
29+
}
30+
```
31+
32+
<!-- schema generated by tfplugindocs -->
33+
## Schema
34+
35+
### Required
36+
37+
- `milestone_id` (Number) The instance-wide ID of the project’s milestone.
38+
- `project` (String) The ID or URL-encoded path of the project owned by the authenticated user.
39+
40+
### Read-Only
41+
42+
- `created_at` (String) The time of creation of the milestone. Date time string, ISO 8601 formatted, for example 2016-03-11T03:45:40Z.
43+
- `description` (String) The description of the milestone.
44+
- `due_date` (String) The due date of the milestone. Date time string in the format YYYY-MM-DD, for example 2016-03-11.
45+
- `expired` (Boolean) Bool, true if milestore expired.
46+
- `id` (String) The ID of this resource.
47+
- `iid` (Number) The ID of the project's milestone.
48+
- `project_id` (Number) The project ID of milestone.
49+
- `start_date` (String) The start date of the milestone. Date time string in the format YYYY-MM-DD, for example 2016-03-11.
50+
- `state` (String) The state of the milestone. Valid values are: `active`, `closed`.
51+
- `title` (String) The title of a milestone.
52+
- `updated_at` (String) The last update time of the milestone. Date time string, ISO 8601 formatted, for example 2016-03-11T03:45:40Z.
53+
- `web_url` (String) The web URL of the milestone.
54+
55+
+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "gitlab_project_milestones Data Source - terraform-provider-gitlab"
4+
subcategory: ""
5+
description: |-
6+
The gitlab_project_milestones data source allows get details of a project milestones.
7+
Upstream API: GitLab REST API docs https://docs.gitlab.com/ee/api/milestones.html
8+
---
9+
10+
# gitlab_project_milestones (Data Source)
11+
12+
The `gitlab_project_milestones` data source allows get details of a project milestones.
13+
14+
**Upstream API**: [GitLab REST API docs](https://docs.gitlab.com/ee/api/milestones.html)
15+
16+
## Example Usage
17+
18+
```terraform
19+
# By project ID
20+
data "gitlab_project_milestones" "example" {
21+
project = "12345"
22+
}
23+
24+
# By project full path
25+
data "gitlab_project_milestones" "example" {
26+
project = "foo/bar"
27+
}
28+
```
29+
30+
<!-- schema generated by tfplugindocs -->
31+
## Schema
32+
33+
### Required
34+
35+
- `project` (String) The ID or URL-encoded path of the project owned by the authenticated user.
36+
37+
### Optional
38+
39+
- `iids` (List of Number) Return only the milestones having the given `iid` (Note: ignored if `include_parent_milestones` is set as `true`).
40+
- `include_parent_milestones` (Boolean) Include group milestones from parent group and its ancestors. Introduced in GitLab 13.4.
41+
- `search` (String) Return only milestones with a title or description matching the provided string.
42+
- `state` (String) Return only `active` or `closed` milestones.
43+
- `title` (String) Return only the milestones having the given `title`.
44+
45+
### Read-Only
46+
47+
- `id` (String) The ID of this resource.
48+
- `milestones` (List of Object) List of milestones from a project. (see [below for nested schema](#nestedatt--milestones))
49+
50+
<a id="nestedatt--milestones"></a>
51+
### Nested Schema for `milestones`
52+
53+
Read-Only:
54+
55+
- `created_at` (String)
56+
- `description` (String)
57+
- `due_date` (String)
58+
- `expired` (Boolean)
59+
- `iid` (Number)
60+
- `milestone_id` (Number)
61+
- `project` (String)
62+
- `project_id` (Number)
63+
- `start_date` (String)
64+
- `state` (String)
65+
- `title` (String)
66+
- `updated_at` (String)
67+
- `web_url` (String)
68+
69+

docs/resources/project_milestone.md

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "gitlab_project_milestone Resource - terraform-provider-gitlab"
4+
subcategory: ""
5+
description: |-
6+
The gitlab_project_milestone resource allows to manage the lifecycle of a project milestone.
7+
Upstream API: GitLab REST API docs https://docs.gitlab.com/ee/api/milestones.html
8+
---
9+
10+
# gitlab_project_milestone (Resource)
11+
12+
The `gitlab_project_milestone` resource allows to manage the lifecycle of a project milestone.
13+
14+
**Upstream API**: [GitLab REST API docs](https://docs.gitlab.com/ee/api/milestones.html)
15+
16+
## Example Usage
17+
18+
```terraform
19+
# Create a project for the milestone to use
20+
resource "gitlab_project" "example" {
21+
name = "example"
22+
description = "An example project"
23+
namespace_id = gitlab_group.example.id
24+
}
25+
26+
resource "gitlab_project_milestone" "example" {
27+
project = gitlab_project.example.id
28+
title = "example"
29+
}
30+
```
31+
32+
<!-- schema generated by tfplugindocs -->
33+
## Schema
34+
35+
### Required
36+
37+
- `project` (String) The ID or URL-encoded path of the project owned by the authenticated user.
38+
- `title` (String) The title of a milestone.
39+
40+
### Optional
41+
42+
- `description` (String) The description of the milestone.
43+
- `due_date` (String) The due date of the milestone. Date time string in the format YYYY-MM-DD, for example 2016-03-11.
44+
- `start_date` (String) The start date of the milestone. Date time string in the format YYYY-MM-DD, for example 2016-03-11.
45+
- `state` (String) The state of the milestone. Valid values are: `active`, `closed`.
46+
47+
### Read-Only
48+
49+
- `created_at` (String) The time of creation of the milestone. Date time string, ISO 8601 formatted, for example 2016-03-11T03:45:40Z.
50+
- `expired` (Boolean) Bool, true if milestore expired.
51+
- `id` (String) The ID of this resource.
52+
- `iid` (Number) The ID of the project's milestone.
53+
- `milestone_id` (Number) The instance-wide ID of the project’s milestone.
54+
- `project_id` (Number) The project ID of milestone.
55+
- `updated_at` (String) The last update time of the milestone. Date time string, ISO 8601 formatted, for example 2016-03-11T03:45:40Z.
56+
- `web_url` (String) The web URL of the milestone.
57+
58+
## Import
59+
60+
Import is supported using the following syntax:
61+
62+
```shell
63+
# Gitlab project milestone can be imported with a key composed of `<project>:<milestone_id>`, e.g.
64+
terraform import gitlab_project_milestone.example "12345:11"
65+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# By project ID
2+
data "gitlab_project_milestone" "example" {
3+
project = "12345"
4+
milestone_id = 10
5+
}
6+
7+
# By project full path
8+
data "gitlab_project_milestone" "example" {
9+
project = "foo/bar"
10+
milestone_id = 10
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# By project ID
2+
data "gitlab_project_milestones" "example" {
3+
project = "12345"
4+
}
5+
6+
# By project full path
7+
data "gitlab_project_milestones" "example" {
8+
project = "foo/bar"
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Gitlab project milestone can be imported with a key composed of `<project>:<milestone_id>`, e.g.
2+
terraform import gitlab_project_milestone.example "12345:11"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Create a project for the milestone to use
2+
resource "gitlab_project" "example" {
3+
name = "example"
4+
description = "An example project"
5+
namespace_id = gitlab_group.example.id
6+
}
7+
8+
resource "gitlab_project_milestone" "example" {
9+
project = gitlab_project.example.id
10+
title = "example"
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package provider
2+
3+
import (
4+
"context"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
7+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
8+
"github.com/xanzy/go-gitlab"
9+
)
10+
11+
var _ = registerDataSource("gitlab_project_milestone", func() *schema.Resource {
12+
return &schema.Resource{
13+
Description: `The ` + "`gitlab_project_milestone`" + ` data source allows get details of a project milestone.
14+
15+
**Upstream API**: [GitLab REST API docs](https://docs.gitlab.com/ee/api/milestones.html)`,
16+
17+
ReadContext: dataSourceGitlabProjectMilestoneRead,
18+
Schema: datasourceSchemaFromResourceSchema(gitlabProjectMilestoneGetSchema(), []string{"project", "milestone_id"}, nil),
19+
}
20+
})
21+
22+
func dataSourceGitlabProjectMilestoneRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
23+
client := meta.(*gitlab.Client)
24+
project := d.Get("project").(string)
25+
milestoneID := d.Get("milestone_id").(int)
26+
27+
milestone, _, err := client.Milestones.GetMilestone(project, milestoneID, gitlab.WithContext(ctx))
28+
if err != nil {
29+
return diag.FromErr(err)
30+
}
31+
d.SetId(resourceGitLabProjectMilestoneBuildId(project, milestone.ID))
32+
stateMap := gitlabProjectMilestoneToStateMap(project, milestone)
33+
34+
if err := setStateMapInResourceData(stateMap, d); err != nil {
35+
return diag.FromErr(err)
36+
}
37+
return nil
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//go:build acceptance
2+
// +build acceptance
3+
4+
package provider
5+
6+
import (
7+
"fmt"
8+
"testing"
9+
10+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
11+
)
12+
13+
func TestAccDataSourceGitlabProjectMilestone_basic(t *testing.T) {
14+
15+
testProject := testAccCreateProject(t)
16+
testMilestone := testAccAddProjectMilestones(t, testProject, 1)[0]
17+
18+
resource.Test(t, resource.TestCase{
19+
ProviderFactories: providerFactories,
20+
Steps: []resource.TestStep{
21+
{
22+
Config: fmt.Sprintf(`
23+
data "gitlab_project_milestone" "this" {
24+
project = "%d"
25+
milestone_id = "%d"
26+
}`, testProject.ID, testMilestone.ID),
27+
Check: resource.ComposeTestCheckFunc(
28+
resource.TestCheckResourceAttr("data.gitlab_project_milestone.this", "milestone_id", fmt.Sprintf("%v", testMilestone.ID)),
29+
resource.TestCheckResourceAttr("data.gitlab_project_milestone.this", "title", testMilestone.Title),
30+
resource.TestCheckResourceAttr("data.gitlab_project_milestone.this", "description", testMilestone.Description),
31+
),
32+
},
33+
},
34+
})
35+
}

0 commit comments

Comments
 (0)