forked from russellcardullo/terraform-provider-pingdom
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathdata_source_pingdom_teams.go
54 lines (46 loc) · 1.22 KB
/
data_source_pingdom_teams.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
package pingdom
import (
"context"
"strconv"
"time"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func dataSourcePingdomTeams() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourcePingdomTeamsRead,
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 dataSourcePingdomTeamsRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(*Clients).Pingdom
teams, err := client.Teams.List()
if err != nil {
return diag.Errorf("Error retrieving teams: %s", err)
}
var ids = make([]int, 0, len(teams))
var names = make([]string, 0, len(teams))
for _, team := range teams {
ids = append(ids, team.ID)
names = append(names, team.Name)
}
d.SetId(strconv.FormatInt(time.Now().Unix(), 10))
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
}