-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathdata_source_projects.go
46 lines (38 loc) · 1.33 KB
/
data_source_projects.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package octopusdeploy
import (
"context"
"time"
"github.com/OctopusDeploy/go-octopusdeploy/octopusdeploy"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func dataSourceProjects() *schema.Resource {
return &schema.Resource{
Description: "Provides information about existing projects.",
ReadContext: dataSourceProjectsRead,
Schema: getProjectDataSchema(),
}
}
func dataSourceProjectsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
query := octopusdeploy.ProjectsQuery{
ClonedFromProjectID: d.Get("cloned_from_project_id").(string),
IDs: expandArray(d.Get("ids").([]interface{})),
IsClone: d.Get("is_clone").(bool),
Name: d.Get("name").(string),
PartialName: d.Get("partial_name").(string),
Skip: d.Get("skip").(int),
Take: d.Get("take").(int),
}
client := m.(*octopusdeploy.Client)
projects, err := client.Projects.Get(query)
if err != nil {
return diag.FromErr(err)
}
flattenedProjects := []interface{}{}
for _, project := range projects.Items {
flattenedProjects = append(flattenedProjects, flattenProject(project))
}
d.Set("projects", flattenedProjects)
d.SetId("Projects " + time.Now().UTC().String())
return nil
}