-
Notifications
You must be signed in to change notification settings - Fork 137
/
data_source_fastly_tls_private_key_ids.go
47 lines (38 loc) · 1.24 KB
/
data_source_fastly_tls_private_key_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
47
package fastly
import (
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/helper/hashcode"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)
func dataSourceFastlyTLSPrivateKeyIDs() *schema.Resource {
return &schema.Resource{
Read: dataSourceFastlyTLSPrivateKeyIDsRead,
Schema: map[string]*schema.Schema{
"ids": {
Type: schema.TypeSet,
Description: "List of IDs of the TLS private keys.",
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
},
}
}
func dataSourceFastlyTLSPrivateKeyIDsRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*FastlyClient).conn
keys, err := listTLSPrivateKeys(conn)
if err != nil {
return err
}
var ids []string
for _, key := range keys {
ids = append(ids, key.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
if err := d.Set("ids", ids); err != nil {
return err
}
return nil
}