-
Notifications
You must be signed in to change notification settings - Fork 219
/
data_source_probes.go
53 lines (46 loc) · 1.3 KB
/
data_source_probes.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
package syntheticmonitoring
import (
"context"
"github.com/grafana/terraform-provider-grafana/internal/common"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func DataSourceProbes() *schema.Resource {
return &schema.Resource{
Description: "Data source for retrieving all probes.",
ReadContext: DataSourceProbesRead,
Schema: map[string]*schema.Schema{
"filter_deprecated": {
Type: schema.TypeBool,
Description: "If true, only probes that are not deprecated will be returned.",
Optional: true,
Default: true,
},
"probes": {
Description: "Map of probes with their names as keys and IDs as values.",
Type: schema.TypeMap,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
},
}
}
func DataSourceProbesRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
c := meta.(*common.Client).SMAPI
var diags diag.Diagnostics
prbs, err := c.ListProbes(ctx)
if err != nil {
return diag.FromErr(err)
}
probes := make(map[string]interface{}, len(prbs))
for _, p := range prbs {
if !p.Deprecated || !d.Get("filter_deprecated").(bool) {
probes[p.Name] = p.Id
}
}
d.SetId("probes")
d.Set("probes", probes)
return diags
}