-
Notifications
You must be signed in to change notification settings - Fork 132
/
data_source_fastly_tls_certificate_ids.go
46 lines (39 loc) · 1.29 KB
/
data_source_fastly_tls_certificate_ids.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 fastly
import (
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/helper/hashcode"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)
func dataSourceFastlyTLSCertificateIDs() *schema.Resource {
return &schema.Resource{
Read: dataSourceFastlyTLSCertificateIDsRead,
Schema: map[string]*schema.Schema{
"ids": {
Type: schema.TypeSet,
Description: "List of IDs corresponding to Custom TLS certificates.",
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
},
}
}
func dataSourceFastlyTLSCertificateIDsRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*FastlyClient).conn
certificates, err := listTLSCertificates(conn)
if err != nil {
return err
}
var ids []string
for _, certificate := range certificates {
ids = append(ids, certificate.ID)
}
// 2.x upgrade note - `hashcode.String` was removed from the SDK
// Code will need to be copied into this repository
// https://www.terraform.io/docs/extend/guides/v2-upgrade-guide.html#removal-of-helper-hashcode-package
d.SetId(fmt.Sprintf("%d", hashcode.String(""))) // if other filters are added to this data source, they should be included in this hashcode instead of the empty string
err = d.Set("ids", ids)
if err != nil {
return err
}
return nil
}