-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathschema_project_group.go
81 lines (65 loc) · 2.05 KB
/
schema_project_group.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package octopusdeploy
import (
"context"
"github.com/OctopusDeploy/go-octopusdeploy/octopusdeploy"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func expandProjectGroup(d *schema.ResourceData) *octopusdeploy.ProjectGroup {
name := d.Get("name").(string)
projectGroup := octopusdeploy.NewProjectGroup(name)
projectGroup.ID = d.Id()
if v, ok := d.GetOk("description"); ok {
projectGroup.Description = v.(string)
}
if v, ok := d.GetOk("retention_policy_id"); ok {
projectGroup.RetentionPolicyID = v.(string)
}
return projectGroup
}
func flattenProjectGroup(projectGroup *octopusdeploy.ProjectGroup) map[string]interface{} {
if projectGroup == nil {
return nil
}
return map[string]interface{}{
"description": projectGroup.Description,
"id": projectGroup.GetID(),
"name": projectGroup.Name,
"retention_policy_id": projectGroup.RetentionPolicyID,
}
}
func getProjectGroupDataSchema() map[string]*schema.Schema {
dataSchema := getProjectGroupSchema()
setDataSchema(&dataSchema)
return map[string]*schema.Schema{
"id": getDataSchemaID(),
"ids": getQueryIDs(),
"partial_name": getQueryPartialName(),
"project_groups": {
Computed: true,
Description: "A list of project groups that match the filter(s).",
Elem: &schema.Resource{Schema: dataSchema},
Optional: true,
Type: schema.TypeList,
},
"skip": getQuerySkip(),
"take": getQueryTake(),
}
}
func getProjectGroupSchema() map[string]*schema.Schema {
return map[string]*schema.Schema{
"description": getDescriptionSchema(),
"id": getIDSchema(),
"name": getNameSchema(true),
"retention_policy_id": {
Optional: true,
Type: schema.TypeString,
},
}
}
func setProjectGroup(ctx context.Context, d *schema.ResourceData, projectGroup *octopusdeploy.ProjectGroup) error {
d.Set("description", projectGroup.Description)
d.Set("name", projectGroup.Name)
d.Set("retention_policy_id", projectGroup.RetentionPolicyID)
d.SetId(projectGroup.GetID())
return nil
}