Skip to content

Commit 0e6ec6d

Browse files
Datasources: Support new attributes (#506)
* Datasources: Support new attributes Adds `xpack_enabled` and `manage_alerts` to datasource json_data Closes #458 Closes #300 * Generate docs
1 parent a67e4a2 commit 0e6ec6d

File tree

5 files changed

+34
-4
lines changed

5 files changed

+34
-4
lines changed

docs/resources/data_source.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ Optional:
130130
- `interval` (String) (Elasticsearch) Index date time format. nil(No Pattern), 'Hourly', 'Daily', 'Weekly', 'Monthly' or 'Yearly'.
131131
- `log_level_field` (String) (Elasticsearch) Which field should be used to indicate the priority of the log message.
132132
- `log_message_field` (String) (Elasticsearch) Which field should be used as the log message.
133+
- `manage_alerts` (Boolean) (Prometheus) Manage alerts.
133134
- `max_concurrent_shard_requests` (Number) (Elasticsearch) Maximum number of concurrent shard requests.
134135
- `max_idle_conns` (Number) (MySQL, PostgreSQL and MSSQL) Maximum number of connections in the idle connection pool (Grafana v5.4+).
135136
- `max_lines` (Number) (Loki) Upper limit for the number of log lines returned by Loki
@@ -162,6 +163,7 @@ Optional:
162163
- `tsdb_version` (Number) (OpenTSDB) Version.
163164
- `version` (String) (InfluxDB) InfluxQL or Flux.
164165
- `workgroup` (String) (Athena) Workgroup to use.
166+
- `xpack_enabled` (Boolean) (Elasticsearch) Enable X-Pack support.
165167

166168
<a id="nestedblock--json_data--derived_field"></a>
167169
### Nested Schema for `json_data.derived_field`

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.18
55
require (
66
github.com/Masterminds/semver/v3 v3.1.1
77
github.com/grafana/amixr-api-go-client v0.0.1
8-
github.com/grafana/grafana-api-golang-client v0.5.3
8+
github.com/grafana/grafana-api-golang-client v0.6.0
99
github.com/grafana/machine-learning-go-client v0.1.1
1010
github.com/grafana/synthetic-monitoring-agent v0.8.2
1111
github.com/grafana/synthetic-monitoring-api-go-client v0.6.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
114114
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
115115
github.com/grafana/amixr-api-go-client v0.0.1 h1:vj5gNxZ1LC3Yu6AavRfDKdqzq1h4WR5wXZEyHLaGkm8=
116116
github.com/grafana/amixr-api-go-client v0.0.1/go.mod h1:N6x26XUrM5zGtK5zL5vNJnAn2JFMxLFPPLTw/6pDkFE=
117-
github.com/grafana/grafana-api-golang-client v0.5.3 h1:QoIesfzqt4Ges7ocNDatHIBRjagGInOJ50LSIfzPmp4=
118-
github.com/grafana/grafana-api-golang-client v0.5.3/go.mod h1:24W29gPe9yl0/3A9X624TPkAOR8DpHno490cPwnkv8E=
117+
github.com/grafana/grafana-api-golang-client v0.6.0 h1:vIHRlBFuhv8RblcinH31ez1+JYYFhuJGx4kIRKlT6l8=
118+
github.com/grafana/grafana-api-golang-client v0.6.0/go.mod h1:24W29gPe9yl0/3A9X624TPkAOR8DpHno490cPwnkv8E=
119119
github.com/grafana/machine-learning-go-client v0.1.1 h1:Gw6cX8xAd6IVF2LApkXOIdBK8Gzz07B3jQPukecw7fc=
120120
github.com/grafana/machine-learning-go-client v0.1.1/go.mod h1:QFfZz8NkqVF8++skjkKQXJEZfpCYd8S0yTWJUpsLLTA=
121121
github.com/grafana/synthetic-monitoring-agent v0.8.2 h1:retJc4xWxoHwqhWa4HZ9t4mO+Je0DWm8wCGdPW2hmuw=

grafana/resource_data_source.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,11 @@ source selected (via the 'type' argument).
262262
Optional: true,
263263
Description: "(Elasticsearch) Which field should be used as the log message.",
264264
},
265+
"manage_alerts": {
266+
Type: schema.TypeBool,
267+
Optional: true,
268+
Description: "(Prometheus) Manage alerts.",
269+
},
265270
"max_concurrent_shard_requests": {
266271
Type: schema.TypeInt,
267272
Optional: true,
@@ -423,6 +428,11 @@ source selected (via the 'type' argument).
423428
Optional: true,
424429
Description: "(Athena) Workgroup to use.",
425430
},
431+
"xpack_enabled": {
432+
Type: schema.TypeBool,
433+
Optional: true,
434+
Description: "(Elasticsearch) Enable X-Pack support.",
435+
},
426436
},
427437
},
428438
},
@@ -707,6 +717,7 @@ func makeJSONData(d *schema.ResourceData) gapi.JSONData {
707717
Implementation: d.Get("json_data.0.implementation").(string),
708718
LogLevelField: d.Get("json_data.0.log_level_field").(string),
709719
LogMessageField: d.Get("json_data.0.log_message_field").(string),
720+
ManageAlerts: d.Get("json_data.0.manage_alerts").(bool),
710721
MaxConcurrentShardRequests: int64(d.Get("json_data.0.max_concurrent_shard_requests").(int)),
711722
MaxIdleConns: int64(d.Get("json_data.0.max_idle_conns").(int)),
712723
MaxLines: d.Get("json_data.0.max_lines").(int),
@@ -739,6 +750,7 @@ func makeJSONData(d *schema.ResourceData) gapi.JSONData {
739750
TsdbVersion: int64(d.Get("json_data.0.tsdb_version").(int)),
740751
Version: d.Get("json_data.0.version").(string),
741752
Workgroup: d.Get("json_data.0.workgroup").(string),
753+
XpackEnabled: d.Get("json_data.0.xpack_enabled").(bool),
742754
}
743755
}
744756

grafana/resource_data_source_test.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package grafana
22

33
import (
4+
"errors"
45
"fmt"
56
"reflect"
67
"strconv"
@@ -214,6 +215,7 @@ func TestAccDataSource_basic(t *testing.T) {
214215
log_message_field = "message"
215216
log_level_field = "fields.level"
216217
max_concurrent_shard_requests = 8
218+
xpack_enabled = true
217219
}
218220
}
219221
`,
@@ -229,6 +231,17 @@ func TestAccDataSource_basic(t *testing.T) {
229231
"json_data.0.log_level_field": "fields.level",
230232
"json_data.0.max_concurrent_shard_requests": "8",
231233
},
234+
additionalChecks: []resource.TestCheckFunc{
235+
func(s *terraform.State) error {
236+
if dataSource.Name != "elasticsearch" {
237+
return fmt.Errorf("bad name: %s", dataSource.Name)
238+
}
239+
if dataSource.JSONData.XpackEnabled != true {
240+
return errors.New("xpack_enabled should be true")
241+
}
242+
return nil
243+
},
244+
},
232245
},
233246
{
234247
resource: "grafana_data_source.opentsdb",
@@ -372,6 +385,7 @@ func TestAccDataSource_basic(t *testing.T) {
372385
sigv4_auth = true
373386
sigv4_auth_type = "default"
374387
sigv4_region = "eu-west-1"
388+
manage_alerts = true
375389
}
376390
377391
http_headers = {
@@ -398,10 +412,12 @@ func TestAccDataSource_basic(t *testing.T) {
398412
if len(dataSource.HTTPHeaders) != 1 {
399413
return fmt.Errorf("expected 1 http header, got %d", len(dataSource.HTTPHeaders))
400414
}
401-
402415
if _, ok := dataSource.HTTPHeaders["header1"]; !ok {
403416
return fmt.Errorf("http header header1 not found")
404417
}
418+
if dataSource.JSONData.ManageAlerts != true {
419+
return errors.New("expected manage_alerts to be true")
420+
}
405421
return nil
406422
},
407423
},

0 commit comments

Comments
 (0)