forked from russellcardullo/terraform-provider-pingdom
-
Notifications
You must be signed in to change notification settings - Fork 7
/
data_source_pingdom_integrations.go
59 lines (50 loc) · 1.4 KB
/
data_source_pingdom_integrations.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
49
50
51
52
53
54
55
56
57
58
59
package pingdom
import (
"context"
"fmt"
"log"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func dataSourcePingdomIntegrations() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourcePingdomIntegrationsRead,
Schema: map[string]*schema.Schema{
"names": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"ids": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeInt},
},
},
}
}
func dataSourcePingdomIntegrationsRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(*Clients).PingdomExt
if client == nil {
return diag.FromErr(fmt.Errorf("Client not correctly configured to use this resource"))
}
integrations, err := client.Integrations.List()
log.Printf("[DEBUG] integrations : %v", integrations)
if err != nil {
return diag.Errorf("Error retrieving team: %s", err)
}
var ids []int
var names []string
for _, integration := range integrations {
ids = append(ids, integration.ID)
names = append(names, integration.UserData["name"])
}
d.SetId(fmt.Sprintf("%d", len(integrations)))
if err := d.Set("ids", ids); err != nil {
return diag.FromErr(err)
}
if err := d.Set("names", names); err != nil {
return diag.FromErr(err)
}
return nil
}