Skip to content

Commit dddf535

Browse files
datasource: add http headers support (#261)
* datasource: add http headers support Signed-off-by: Guillaume Delbergue <[email protected]> * Add test + Switch to newly released v0.2.1 client Co-authored-by: Julien Duchesne <[email protected]>
1 parent d3de24b commit dddf535

File tree

5 files changed

+315
-277
lines changed

5 files changed

+315
-277
lines changed

docs/resources/data_source.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ resource "grafana_data_source" "stackdriver" {
8888
- **basic_auth_password** (String, Sensitive) Basic auth password. Defaults to ``.
8989
- **basic_auth_username** (String) Basic auth username. Defaults to ``.
9090
- **database_name** (String) (Required by some data source types) The name of the database to use on the selected data source server. Defaults to ``.
91+
- **http_headers** (Map of String, Sensitive) Custom HTTP headers
9192
- **id** (String) The ID of this resource.
9293
- **is_default** (Boolean) Whether to set the data source as default. This should only be `true` to a single data source. Defaults to `false`.
9394
- **json_data** (Block List) (Required by some data source types) (see [below for nested schema](#nestedblock--json_data))

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/grafana/terraform-provider-grafana
33
go 1.16
44

55
require (
6-
github.com/grafana/grafana-api-golang-client v0.1.3
6+
github.com/grafana/grafana-api-golang-client v0.2.1
77
github.com/grafana/synthetic-monitoring-agent v0.4.1
88
github.com/grafana/synthetic-monitoring-api-go-client v0.3.0
99
github.com/hashicorp/go-cleanhttp v0.5.2

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,8 +452,8 @@ github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51
452452
github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
453453
github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
454454
github.com/gorilla/websocket v0.0.0-20170926233335-4201258b820c/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
455-
github.com/grafana/grafana-api-golang-client v0.1.3 h1:p0f8FB0/UlBX3nXv+Lt+dmms5p5cmp6hxuipio93lYc=
456-
github.com/grafana/grafana-api-golang-client v0.1.3/go.mod h1:24W29gPe9yl0/3A9X624TPkAOR8DpHno490cPwnkv8E=
455+
github.com/grafana/grafana-api-golang-client v0.2.1 h1:5OizQpq+WP+A6t+wHoYCOrmbytWQMgnWwPfzXqSBGrI=
456+
github.com/grafana/grafana-api-golang-client v0.2.1/go.mod h1:24W29gPe9yl0/3A9X624TPkAOR8DpHno490cPwnkv8E=
457457
github.com/grafana/synthetic-monitoring-agent v0.3.0/go.mod h1:P8WTBnw3SIZW5Nm5obOlSKvD887IxAfbrJkSnoZyIlA=
458458
github.com/grafana/synthetic-monitoring-agent v0.4.1 h1:RiVOHi059tYIDixXPxmFQ2vCWCY4Vksslpfm5gNkgnQ=
459459
github.com/grafana/synthetic-monitoring-agent v0.4.1/go.mod h1:hcx3Pe76ixYsbjtM0eFpyE1bzPxiFgJIyXtdqgPeIkk=

grafana/resource_data_source.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package grafana
22

33
import (
44
"context"
5+
"fmt"
56
"log"
67
"regexp"
78
"strconv"
@@ -62,6 +63,15 @@ source selected (via the 'type' argument).
6263
Default: "",
6364
Description: "(Required by some data source types) The name of the database to use on the selected data source server.",
6465
},
66+
"http_headers": {
67+
Type: schema.TypeMap,
68+
Optional: true,
69+
Sensitive: true,
70+
Description: "Custom HTTP headers",
71+
Elem: &schema.Schema{
72+
Type: schema.TypeString,
73+
},
74+
},
6575
"is_default": {
6676
Type: schema.TypeBool,
6777
Optional: true,
@@ -481,6 +491,11 @@ func makeDataSource(d *schema.ResourceData) (*gapi.DataSource, error) {
481491
id, err = strconv.ParseInt(idStr, 10, 64)
482492
}
483493

494+
httpHeaders := make(map[string]string)
495+
for key, value := range d.Get("http_headers").(map[string]interface{}) {
496+
httpHeaders[key] = fmt.Sprintf("%v", value)
497+
}
498+
484499
return &gapi.DataSource{
485500
ID: id,
486501
Name: d.Get("name").(string),
@@ -495,6 +510,7 @@ func makeDataSource(d *schema.ResourceData) (*gapi.DataSource, error) {
495510
BasicAuthUser: d.Get("basic_auth_username").(string),
496511
BasicAuthPassword: d.Get("basic_auth_password").(string),
497512
UID: d.Get("uid").(string),
513+
HTTPHeaders: httpHeaders,
498514
JSONData: makeJSONData(d),
499515
SecureJSONData: makeSecureJSONData(d),
500516
}, err

0 commit comments

Comments
 (0)