Skip to content

Commit 274a570

Browse files
authored
Add UID to datasource reosurce and test (#315)
* Add UID to datasource reosurce and test * ✏️ update docs as per failing CI
1 parent 786739f commit 274a570

File tree

5 files changed

+17
-1
lines changed

5 files changed

+17
-1
lines changed

docs/resources/data_source.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ resource "grafana_data_source" "stackdriver" {
9393
- **json_data** (Block List) (Required by some data source types) (see [below for nested schema](#nestedblock--json_data))
9494
- **password** (String, Sensitive) (Required by some data source types) The password to use to authenticate to the data source. Defaults to ``.
9595
- **secure_json_data** (Block List) (see [below for nested schema](#nestedblock--secure_json_data))
96+
- **uid** (String) Unique identifier. If unset, this will be automatically generated.
9697
- **url** (String) The URL for the data source. The type of URL required varies depending on the chosen data source type.
9798
- **username** (String) (Required by some data source types) The username to use to authenticate to the data source. Defaults to ``.
9899

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.1
6+
github.com/grafana/grafana-api-golang-client v0.1.2
77
github.com/grafana/synthetic-monitoring-agent v0.3.3
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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,8 @@ github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2z
454454
github.com/gorilla/websocket v0.0.0-20170926233335-4201258b820c/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
455455
github.com/grafana/grafana-api-golang-client v0.1.1 h1:qS/i3dxITGyDRqYuBLk679SjpSwPQ3VZyxuTsKq1Bas=
456456
github.com/grafana/grafana-api-golang-client v0.1.1/go.mod h1:24W29gPe9yl0/3A9X624TPkAOR8DpHno490cPwnkv8E=
457+
github.com/grafana/grafana-api-golang-client v0.1.2 h1:dutE6hUVSJcpb4EtvjfSM8VQHh2kYxvGEeE8xVxUjWA=
458+
github.com/grafana/grafana-api-golang-client v0.1.2/go.mod h1:24W29gPe9yl0/3A9X624TPkAOR8DpHno490cPwnkv8E=
457459
github.com/grafana/synthetic-monitoring-agent v0.3.0/go.mod h1:P8WTBnw3SIZW5Nm5obOlSKvD887IxAfbrJkSnoZyIlA=
458460
github.com/grafana/synthetic-monitoring-agent v0.3.3 h1:/MM1vm/BwnbwQ2/aEwKbEpf01O4O3GhrcOofY4A0V9Q=
459461
github.com/grafana/synthetic-monitoring-agent v0.3.3/go.mod h1:qyo27gOTdj8K/dKkd+/SJ0M0zlnCV7t9nwVK+iLkVrk=

grafana/resource_data_source.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ source selected (via the 'type' argument).
6868
Default: false,
6969
Description: "Whether to set the data source as default. This should only be `true` to a single data source.",
7070
},
71+
"uid": {
72+
Type: schema.TypeString,
73+
Optional: true,
74+
Computed: true,
75+
Description: "Unique identifier. If unset, this will be automatically generated.",
76+
},
7177
"json_data": {
7278
Type: schema.TypeList,
7379
Optional: true,
@@ -439,6 +445,7 @@ func ReadDataSource(ctx context.Context, d *schema.ResourceData, meta interface{
439445
d.Set("type", dataSource.Type)
440446
d.Set("url", dataSource.URL)
441447
d.Set("username", dataSource.User)
448+
d.Set("uid", dataSource.UID)
442449

443450
// TODO: these fields should be migrated to SecureJSONData.
444451
d.Set("basic_auth_enabled", dataSource.BasicAuth)
@@ -487,6 +494,7 @@ func makeDataSource(d *schema.ResourceData) (*gapi.DataSource, error) {
487494
BasicAuth: d.Get("basic_auth_enabled").(bool),
488495
BasicAuthUser: d.Get("basic_auth_username").(string),
489496
BasicAuthPassword: d.Get("basic_auth_password").(string),
497+
UID: d.Get("uid").(string),
490498
JSONData: makeJSONData(d),
491499
SecureJSONData: makeSecureJSONData(d),
492500
}, err

grafana/resource_data_source_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,11 @@ func TestAccDataSource_basic(t *testing.T) {
308308
"id",
309309
idRegexp,
310310
),
311+
resource.TestMatchResourceAttr(
312+
test.resource,
313+
"uid",
314+
uidRegexp,
315+
),
311316
}
312317

313318
// Add custom checks for specified attribute values

0 commit comments

Comments
 (0)