-
Notifications
You must be signed in to change notification settings - Fork 392
/
Copy pathdata_source_datadog_logs_indexes_order.go
48 lines (38 loc) · 1.56 KB
/
data_source_datadog_logs_indexes_order.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
package datadog
import (
"context"
"github.com/terraform-providers/terraform-provider-datadog/datadog/internal/utils"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func dataSourceDatadogLogsIndexesOrder() *schema.Resource {
return &schema.Resource{
Description: "Get the current order of your log indexes.",
ReadContext: dataSourceDatadogLogsIndexesOrderRead,
SchemaFunc: func() map[string]*schema.Schema {
return map[string]*schema.Schema{
// Computed values
"index_names": {
Description: "Array of strings identifying by their name(s) the index(es) of your organization. Logs are tested against the query filter of each index one by one, following the order of the array. Logs are eventually stored in the first matching index.",
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
}
},
}
}
func dataSourceDatadogLogsIndexesOrderRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
providerConf := meta.(*ProviderConfiguration)
apiInstances := providerConf.DatadogApiInstances
auth := providerConf.Auth
logsIndexesOrder, httpresp, err := apiInstances.GetLogsIndexesApiV1().GetLogsIndexOrder(auth)
if err != nil {
return utils.TranslateClientErrorDiag(err, httpresp, "error querying the order of your log indexes")
}
if err := d.Set("index_names", logsIndexesOrder.GetIndexNames()); err != nil {
return diag.FromErr(err)
}
d.SetId("logs-index-order")
return nil
}