-
Notifications
You must be signed in to change notification settings - Fork 134
/
data_source_fastly_tls_configuration_ids.go
43 lines (37 loc) · 1.22 KB
/
data_source_fastly_tls_configuration_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
package fastly
import (
"context"
"fmt"
"github.com/fastly/terraform-provider-fastly/fastly/hashcode"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func dataSourceFastlyTLSConfigurationIDs() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceFastlyTLSConfigurationIDsRead,
Schema: map[string]*schema.Schema{
"ids": {
Type: schema.TypeSet,
Description: "List of IDs corresponding to available TLS configurations.",
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
},
}
}
func dataSourceFastlyTLSConfigurationIDsRead(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
conn := meta.(*FastlyClient).conn
configurations, err := listTLSConfigurations(conn)
if err != nil {
return diag.FromErr(err)
}
var ids []string
for _, configuration := range configurations {
ids = append(ids, configuration.ID)
}
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 diag.FromErr(err)
}
return nil
}