Skip to content

Commit c38af88

Browse files
medainshansnqyr
andcommitted
Add organization id to the provider.
Use the change in grafana/grafana-api-golang-client#9 to apply an organization id to the provider. Usage might look like this: ```hcl provider "grafana" { url = "someurl" auth = "adminuser:somepass" } resource "grafana_organization" "neworg" { name = "neworg" admin = "neworgadmin" } provider "grafana" { alias = "neworg" url = "someurl" auth = "neworgadmin:somepass" org_id = grafana_organization.neworg.org_id } resource "grafana_data_source" "neworg_graphite" { provider = grafana.neworg type = "graphite" name = "neworg-graphite" } ``` Co-authored-by: hansnqyr <[email protected]>
1 parent 6fca1d6 commit c38af88

File tree

5 files changed

+20
-5
lines changed

5 files changed

+20
-5
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ 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-20201019145005-e01a63d40166
6+
github.com/grafana/grafana-api-golang-client v0.0.0-20201028095551-dd7fea8a2fce
77
github.com/hashicorp/go-cleanhttp v0.5.1
88
github.com/hashicorp/hcl v1.0.0 // indirect
99
github.com/hashicorp/terraform v0.12.2

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ github.com/gophercloud/utils v0.0.0-20190128072930-fbb6ab446f01 h1:OgCNGSnEalfkR
139139
github.com/gophercloud/utils v0.0.0-20190128072930-fbb6ab446f01/go.mod h1:wjDF8z83zTeg5eMLml5EBSlAhbF7G8DobyI1YsMuyzw=
140140
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
141141
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
142-
github.com/grafana/grafana-api-golang-client v0.0.0-20201019145005-e01a63d40166 h1:Kl177VV8TQuyCQVYPF3grDYdRcINbSGP2aIuRqM7VZI=
143-
github.com/grafana/grafana-api-golang-client v0.0.0-20201019145005-e01a63d40166/go.mod h1:jFjwT3lvwl4JKqCw3guRJvlQ1/fmhER1h3Zgix3z7jw=
142+
github.com/grafana/grafana-api-golang-client v0.0.0-20201028095551-dd7fea8a2fce h1:98pwTaBO0LTcF6t7j8AIt3PGKdDtZg2/2/RPbr8tf/M=
143+
github.com/grafana/grafana-api-golang-client v0.0.0-20201028095551-dd7fea8a2fce/go.mod h1:jFjwT3lvwl4JKqCw3guRJvlQ1/fmhER1h3Zgix3z7jw=
144144
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
145145
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
146146
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=

grafana/provider.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ func Provider() terraform.ResourceProvider {
2828
DefaultFunc: schema.EnvDefaultFunc("GRAFANA_AUTH", nil),
2929
Description: "Credentials for accessing the Grafana API.",
3030
},
31+
"org_id": {
32+
Type: schema.TypeInt,
33+
Required: true,
34+
DefaultFunc: schema.EnvDefaultFunc("GRAFANA_ORG_ID", 1),
35+
Description: "Organization id for resources",
36+
},
3137
},
3238

3339
ResourcesMap: map[string]*schema.Resource{
@@ -51,6 +57,7 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
5157
cli.Transport = logging.NewTransport("Grafana", cli.Transport)
5258
cfg := gapi.Config{
5359
Client: cli,
60+
OrgID: d.Get("org_id").(int64),
5461
}
5562
if len(auth) == 2 {
5663
cfg.BasicAuth = url.UserPassword(auth[0], auth[1])

grafana/provider_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,7 @@ func testAccPreCheck(t *testing.T) {
5151
if v := os.Getenv("GRAFANA_AUTH"); v == "" {
5252
t.Fatal("GRAFANA_AUTH must be set for acceptance tests")
5353
}
54+
if v := os.Getenv("GRAFANA_AUTH"); v == "" {
55+
t.Fatal("GRAFANA_AUTH must be set for acceptance tests")
56+
}
5457
}

website/docs/index.html.markdown

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,19 @@ The provider configuration block accepts the following arguments:
2222
are provided in a single string and separated by a colon. May alternatively
2323
be set via the ``GRAFANA_AUTH`` environment variable.
2424

25+
* org_id - (Required) The organization id to operate on within grafana.
26+
Default org_id is 1. May alternatively be set via the
27+
GRAFANA_ORG_ID environment variable.
28+
2529
Use the navigation to the left to read about the available resources.
2630

2731
## Example Usage
2832

2933
```hcl
3034
provider "grafana" {
31-
url = "http://grafana.example.com/"
32-
auth = "1234abcd"
35+
url = "http://grafana.example.com/"
36+
auth = "1234abcd"
37+
org_id = 1
3338
}
3439
3540
resource "grafana_dashboard" "metrics" {

0 commit comments

Comments
 (0)