-
Notifications
You must be signed in to change notification settings - Fork 65
/
data_source_certificates.go
48 lines (40 loc) · 1.42 KB
/
data_source_certificates.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/octopusdeploy"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func dataSourceCertificates() *schema.Resource {
return &schema.Resource{
Description: "Provides information about existing certificates.",
ReadContext: dataSourceCertificatesRead,
Schema: getCertificateDataSchema(),
}
}
func dataSourceCertificatesRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
query := octopusdeploy.CertificatesQuery{
Archived: d.Get("archived").(string),
FirstResult: d.Get("first_result").(string),
IDs: expandArray(d.Get("ids").([]interface{})),
OrderBy: d.Get("order_by").(string),
PartialName: d.Get("partial_name").(string),
Search: d.Get("search").(string),
Skip: d.Get("skip").(int),
Take: d.Get("take").(int),
Tenant: d.Get("tenant").(string),
}
client := m.(*octopusdeploy.Client)
certificates, err := client.Certificates.Get(query)
if err != nil {
return diag.FromErr(err)
}
flattenedCertificates := []interface{}{}
for _, certificate := range certificates.Items {
flattenedCertificates = append(flattenedCertificates, flattenCertificate(certificate))
}
d.Set("certificates", flattenedCertificates)
d.SetId("Certificates " + time.Now().UTC().String())
return nil
}