Skip to content

Commit 980669e

Browse files
Merge pull request grafana#130 from medains/grafana-api-golang-client-changes
Apply changes to match the change to a Config struct
2 parents 944cf38 + 76ebd3e commit 980669e

31 files changed

+157
-146
lines changed

go.mod

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

55
require (
6-
github.com/grafana/grafana-api-golang-client v0.0.0-20201012135725-c87fc20af1ea
6+
github.com/grafana/grafana-api-golang-client v0.0.0-20201019145005-e01a63d40166
7+
github.com/hashicorp/go-cleanhttp v0.5.1
78
github.com/hashicorp/hcl v1.0.0 // indirect
89
github.com/hashicorp/terraform v0.12.2
910
)

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORR
141141
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
142142
github.com/grafana/grafana-api-golang-client v0.0.0-20201012135725-c87fc20af1ea h1:DB+ppVl+w8B5LtFmpjyuPf9zT6t5j95RzwuP/ypYZeU=
143143
github.com/grafana/grafana-api-golang-client v0.0.0-20201012135725-c87fc20af1ea/go.mod h1:jFjwT3lvwl4JKqCw3guRJvlQ1/fmhER1h3Zgix3z7jw=
144+
github.com/grafana/grafana-api-golang-client v0.0.0-20201019145005-e01a63d40166 h1:Kl177VV8TQuyCQVYPF3grDYdRcINbSGP2aIuRqM7VZI=
145+
github.com/grafana/grafana-api-golang-client v0.0.0-20201019145005-e01a63d40166/go.mod h1:jFjwT3lvwl4JKqCw3guRJvlQ1/fmhER1h3Zgix3z7jw=
144146
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
145147
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
146148
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=

grafana/provider.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package grafana
22

33
import (
4+
"net/url"
5+
"strings"
6+
7+
"github.com/hashicorp/go-cleanhttp"
48
"github.com/hashicorp/terraform/helper/logging"
59
"github.com/hashicorp/terraform/helper/schema"
610
"github.com/hashicorp/terraform/terraform"
@@ -42,15 +46,21 @@ func Provider() terraform.ResourceProvider {
4246
}
4347

4448
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
45-
client, err := gapi.New(
46-
d.Get("auth").(string),
47-
d.Get("url").(string),
48-
)
49+
auth := strings.SplitN(d.Get("auth").(string), ":", 2)
50+
cli := cleanhttp.DefaultClient()
51+
cli.Transport = logging.NewTransport("Grafana", cli.Transport)
52+
cfg := gapi.Config{
53+
Client: cli,
54+
}
55+
if len(auth) == 2 {
56+
cfg.BasicAuth = url.UserPassword(auth[0], auth[1])
57+
} else {
58+
cfg.APIKey = auth[0]
59+
}
60+
client, err := gapi.New(d.Get("url").(string), cfg)
4961
if err != nil {
5062
return nil, err
5163
}
5264

53-
client.Transport = logging.NewTransport("Grafana", client.Transport)
54-
5565
return client, nil
5666
}

grafana/resource_alert_notification.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,12 @@ func ReadAlertNotification(d *schema.ResourceData, meta interface{}) error {
126126
}
127127
}
128128

129-
d.Set("id", alertNotification.Id)
129+
d.Set("id", alertNotification.ID)
130130
d.Set("is_default", alertNotification.IsDefault)
131131
d.Set("name", alertNotification.Name)
132132
d.Set("type", alertNotification.Type)
133133
d.Set("settings", settings)
134-
d.Set("uid", alertNotification.Uid)
134+
d.Set("uid", alertNotification.UID)
135135

136136
return nil
137137
}
@@ -182,11 +182,11 @@ func makeAlertNotification(d *schema.ResourceData) (*gapi.AlertNotification, err
182182
}
183183

184184
return &gapi.AlertNotification{
185-
Id: id,
185+
ID: id,
186186
Name: d.Get("name").(string),
187187
Type: d.Get("type").(string),
188188
IsDefault: d.Get("is_default").(bool),
189-
Uid: d.Get("uid").(string),
189+
UID: d.Get("uid").(string),
190190
SendReminder: sendReminder,
191191
Frequency: frequency,
192192
Settings: settings,

grafana/resource_alert_notification_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func testAccAlertNotificationDefinition(a *gapi.AlertNotification) resource.Test
119119
func testAccAlertNotificationCheckDestroy(a *gapi.AlertNotification) resource.TestCheckFunc {
120120
return func(s *terraform.State) error {
121121
client := testAccProvider.Meta().(*gapi.Client)
122-
alert, err := client.AlertNotification(a.Id)
122+
alert, err := client.AlertNotification(a.ID)
123123
if err == nil && alert != nil {
124124
return fmt.Errorf("alert-notification still exists")
125125
}

grafana/resource_dashboard_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ func testAccDashboardCheckExists(rn string, dashboard *gapi.Dashboard) resource.
124124

125125
func testAccDashboardCheckExistsInFolder(dashboard *gapi.Dashboard, folder *gapi.Folder) resource.TestCheckFunc {
126126
return func(s *terraform.State) error {
127-
if dashboard.Folder != folder.Id && folder.Id != 0 {
128-
return fmt.Errorf("dashboard.Folder(%d) does not match folder.Id(%d)", dashboard.Folder, folder.Id)
127+
if dashboard.Folder != folder.ID && folder.ID != 0 {
128+
return fmt.Errorf("dashboard.Folder(%d) does not match folder.ID(%d)", dashboard.Folder, folder.ID)
129129
}
130130
return nil
131131
}
@@ -159,7 +159,7 @@ func testAccDashboardFolderCheckDestroy(dashboard *gapi.Dashboard, folder *gapi.
159159
if err == nil {
160160
return fmt.Errorf("dashboard still exists")
161161
}
162-
_, err = client.Folder(folder.Id)
162+
_, err = client.Folder(folder.ID)
163163
if err == nil {
164164
return fmt.Errorf("folder still exists")
165165
}

grafana/resource_data_source.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ func ReadDataSource(d *schema.ResourceData, meta interface{}) error {
284284
return err
285285
}
286286

287-
d.Set("id", dataSource.Id)
287+
d.Set("id", dataSource.ID)
288288
d.Set("access_mode", dataSource.Access)
289289
d.Set("basic_auth_enabled", dataSource.BasicAuth)
290290
d.Set("basic_auth_username", dataSource.BasicAuthUser)
@@ -322,7 +322,7 @@ func makeDataSource(d *schema.ResourceData) (*gapi.DataSource, error) {
322322
}
323323

324324
return &gapi.DataSource{
325-
Id: id,
325+
ID: id,
326326
Name: d.Get("name").(string),
327327
Type: d.Get("type").(string),
328328
URL: d.Get("url").(string),
@@ -349,7 +349,7 @@ func makeJSONData(d *schema.ResourceData) gapi.JSONData {
349349
Encrypt: d.Get("json_data.0.encrypt").(string),
350350
EsVersion: int64(d.Get("json_data.0.es_version").(int)),
351351
GraphiteVersion: d.Get("json_data.0.graphite_version").(string),
352-
HttpMethod: d.Get("json_data.0.http_method").(string),
352+
HTTPMethod: d.Get("json_data.0.http_method").(string),
353353
Interval: d.Get("json_data.0.interval").(string),
354354
LogLevelField: d.Get("json_data.0.log_level_field").(string),
355355
LogMessageField: d.Get("json_data.0.log_message_field").(string),
@@ -361,9 +361,9 @@ func makeJSONData(d *schema.ResourceData) gapi.JSONData {
361361
Timescaledb: d.Get("json_data.0.timescaledb").(bool),
362362
TimeField: d.Get("json_data.0.time_field").(string),
363363
TimeInterval: d.Get("json_data.0.time_interval").(string),
364-
TlsAuth: d.Get("json_data.0.tls_auth").(bool),
365-
TlsAuthWithCACert: d.Get("json_data.0.tls_auth_with_ca_cert").(bool),
366-
TlsSkipVerify: d.Get("json_data.0.tls_skip_verify").(bool),
364+
TLSAuth: d.Get("json_data.0.tls_auth").(bool),
365+
TLSAuthWithCACert: d.Get("json_data.0.tls_auth_with_ca_cert").(bool),
366+
TLSSkipVerify: d.Get("json_data.0.tls_skip_verify").(bool),
367367
TsdbResolution: d.Get("json_data.0.tsdb_resolution").(string),
368368
TsdbVersion: d.Get("json_data.0.tsdb_version").(string),
369369
}
@@ -376,8 +376,8 @@ func makeSecureJSONData(d *schema.ResourceData) gapi.SecureJSONData {
376376
Password: d.Get("secure_json_data.0.password").(string),
377377
PrivateKey: d.Get("secure_json_data.0.private_key").(string),
378378
SecretKey: d.Get("secure_json_data.0.secret_key").(string),
379-
TlsCACert: d.Get("secure_json_data.0.tls_ca_cert").(string),
380-
TlsClientCert: d.Get("secure_json_data.0.tls_client_cert").(string),
381-
TlsClientKey: d.Get("secure_json_data.0.tls_client_key").(string),
379+
TLSCACert: d.Get("secure_json_data.0.tls_ca_cert").(string),
380+
TLSClientCert: d.Get("secure_json_data.0.tls_client_cert").(string),
381+
TLSClientKey: d.Get("secure_json_data.0.tls_client_key").(string),
382382
}
383383
}

grafana/resource_data_source_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ func testAccDataSourceCheckExists(rn string, dataSource *gapi.DataSource) resour
348348
func testAccDataSourceCheckDestroy(dataSource *gapi.DataSource) resource.TestCheckFunc {
349349
return func(s *terraform.State) error {
350350
client := testAccProvider.Meta().(*gapi.Client)
351-
_, err := client.DataSource(dataSource.Id)
351+
_, err := client.DataSource(dataSource.ID)
352352
if err == nil {
353353
return fmt.Errorf("data source still exists")
354354
}

grafana/resource_folder.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ func CreateFolder(d *schema.ResourceData, meta interface{}) error {
4343
return err
4444
}
4545

46-
id := strconv.FormatInt(resp.Id, 10)
46+
id := strconv.FormatInt(resp.ID, 10)
4747
d.SetId(id)
48-
d.Set("uid", resp.Uid)
48+
d.Set("uid", resp.UID)
4949
d.Set("title", resp.Title)
5050

5151
return ReadFolder(d, meta)
@@ -70,7 +70,7 @@ func ReadFolder(d *schema.ResourceData, meta interface{}) error {
7070
return err
7171
}
7272

73-
d.SetId(strconv.FormatInt(folder.Id, 10))
73+
d.SetId(strconv.FormatInt(folder.ID, 10))
7474
d.Set("title", folder.Title)
7575

7676
return nil

grafana/resource_folder_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,14 @@ func testAccFolderDisappear(folder *gapi.Folder) resource.TestCheckFunc {
7272
// At this point testAccFolderCheckExists should have been called and
7373
// folder should have been populated
7474
client := testAccProvider.Meta().(*gapi.Client)
75-
return client.DeleteFolder((*folder).Uid)
75+
return client.DeleteFolder((*folder).UID)
7676
}
7777
}
7878

7979
func testAccFolderCheckDestroy(folder *gapi.Folder) resource.TestCheckFunc {
8080
return func(s *terraform.State) error {
8181
client := testAccProvider.Meta().(*gapi.Client)
82-
_, err := client.Folder(folder.Id)
82+
_, err := client.Folder(folder.ID)
8383
if err == nil {
8484
return fmt.Errorf("folder still exists")
8585
}

0 commit comments

Comments
 (0)