-
Notifications
You must be signed in to change notification settings - Fork 65
/
data_source_library_variable_sets.go
48 lines (39 loc) · 1.57 KB
/
data_source_library_variable_sets.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
package octopusdeploy
import (
"context"
"time"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/client"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/libraryvariablesets"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/variables"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func dataSourceLibraryVariableSet() *schema.Resource {
return &schema.Resource{
Description: "Provides information about existing library variable sets.",
ReadContext: dataSourceLibraryVariableSetReadByName,
Schema: getLibraryVariableSetDataSchema(),
}
}
func dataSourceLibraryVariableSetReadByName(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
query := variables.LibraryVariablesQuery{
ContentType: d.Get("content_type").(string),
IDs: expandArray(d.Get("ids").([]interface{})),
PartialName: d.Get("partial_name").(string),
Skip: d.Get("skip").(int),
Take: d.Get("take").(int),
}
spaceID := d.Get("space_id").(string)
client := m.(*client.Client)
existingLibraryVariableSets, err := libraryvariablesets.Get(client, spaceID, query)
if err != nil {
return diag.FromErr(err)
}
flattenedLibraryVariableSets := []interface{}{}
for _, libraryVariableSet := range existingLibraryVariableSets.Items {
flattenedLibraryVariableSets = append(flattenedLibraryVariableSets, flattenLibraryVariableSet(libraryVariableSet))
}
d.Set("library_variable_sets", flattenedLibraryVariableSets)
d.SetId("Library Variables Sets " + time.Now().UTC().String())
return nil
}