-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathschema_library_variable_set.go
100 lines (83 loc) · 2.95 KB
/
schema_library_variable_set.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package octopusdeploy
import (
"context"
"fmt"
"github.com/OctopusDeploy/go-octopusdeploy/octopusdeploy"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func expandLibraryVariableSet(d *schema.ResourceData) *octopusdeploy.LibraryVariableSet {
name := d.Get("name").(string)
libraryVariableSet := octopusdeploy.NewLibraryVariableSet(name)
libraryVariableSet.ID = d.Id()
if v, ok := d.GetOk("description"); ok {
libraryVariableSet.Description = v.(string)
}
if attr, ok := d.GetOk("template"); ok {
tfTemplates := attr.([]interface{})
for _, tfTemplate := range tfTemplates {
template := expandActionTemplateParameter(tfTemplate.(map[string]interface{}))
libraryVariableSet.Templates = append(libraryVariableSet.Templates, template)
}
}
return libraryVariableSet
}
func flattenLibraryVariableSet(libraryVariableSet *octopusdeploy.LibraryVariableSet) map[string]interface{} {
if libraryVariableSet == nil {
return nil
}
return map[string]interface{}{
"description": libraryVariableSet.Description,
"id": libraryVariableSet.GetID(),
"name": libraryVariableSet.Name,
"space_id": libraryVariableSet.SpaceID,
"template": flattenActionTemplateParameters(libraryVariableSet.Templates),
"variable_set_id": libraryVariableSet.VariableSetID,
}
}
func getLibraryVariableSetDataSchema() map[string]*schema.Schema {
dataSchema := getLibraryVariableSetSchema()
setDataSchema(&dataSchema)
return map[string]*schema.Schema{
"content_type": getQueryContentType(),
"id": getDataSchemaID(),
"ids": getQueryIDs(),
"library_variable_sets": {
Computed: true,
Description: "A list of library variable sets that match the filter(s).",
Elem: &schema.Resource{Schema: dataSchema},
Optional: true,
Type: schema.TypeList,
},
"partial_name": getQueryPartialName(),
"skip": getQuerySkip(),
"take": getQueryTake(),
}
}
func getLibraryVariableSetSchema() map[string]*schema.Schema {
return map[string]*schema.Schema{
"description": getDescriptionSchema(),
"id": getIDSchema(),
"name": getNameSchema(true),
"space_id": getSpaceIDSchema(),
"template": {
Optional: true,
Elem: &schema.Resource{Schema: getActionTemplateParameterSchema()},
Type: schema.TypeList,
},
"variable_set_id": {
Computed: true,
Type: schema.TypeString,
},
}
}
func setLibraryVariableSet(ctx context.Context, d *schema.ResourceData, libraryVariableSet *octopusdeploy.LibraryVariableSet) error {
d.Set("description", libraryVariableSet.Description)
d.Set("name", libraryVariableSet.Name)
d.Set("space_id", libraryVariableSet.SpaceID)
d.Set("variable_set_id", libraryVariableSet.VariableSetID)
if err := d.Set("template", flattenActionTemplateParameters(libraryVariableSet.Templates)); err != nil {
return fmt.Errorf("error setting template: %s", err)
}
d.SetId(libraryVariableSet.GetID())
return nil
}