diff --git a/go.mod b/go.mod index 9e9777378..0dc9c05a0 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/terraform-providers/terraform-provider-grafana go 1.14 require ( - github.com/grafana/grafana-api-golang-client v0.0.0-20201019145005-e01a63d40166 + github.com/grafana/grafana-api-golang-client v0.0.0-20201028095551-dd7fea8a2fce github.com/hashicorp/go-cleanhttp v0.5.1 github.com/hashicorp/hcl v1.0.0 // indirect github.com/hashicorp/terraform v0.12.2 diff --git a/go.sum b/go.sum index 703f5ba9a..d4ec75e9e 100644 --- a/go.sum +++ b/go.sum @@ -139,8 +139,8 @@ github.com/gophercloud/utils v0.0.0-20190128072930-fbb6ab446f01 h1:OgCNGSnEalfkR github.com/gophercloud/utils v0.0.0-20190128072930-fbb6ab446f01/go.mod h1:wjDF8z83zTeg5eMLml5EBSlAhbF7G8DobyI1YsMuyzw= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= -github.com/grafana/grafana-api-golang-client v0.0.0-20201019145005-e01a63d40166 h1:Kl177VV8TQuyCQVYPF3grDYdRcINbSGP2aIuRqM7VZI= -github.com/grafana/grafana-api-golang-client v0.0.0-20201019145005-e01a63d40166/go.mod h1:jFjwT3lvwl4JKqCw3guRJvlQ1/fmhER1h3Zgix3z7jw= +github.com/grafana/grafana-api-golang-client v0.0.0-20201028095551-dd7fea8a2fce h1:98pwTaBO0LTcF6t7j8AIt3PGKdDtZg2/2/RPbr8tf/M= +github.com/grafana/grafana-api-golang-client v0.0.0-20201028095551-dd7fea8a2fce/go.mod h1:jFjwT3lvwl4JKqCw3guRJvlQ1/fmhER1h3Zgix3z7jw= github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA= github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= diff --git a/grafana/provider.go b/grafana/provider.go index 427b4c0da..084812467 100644 --- a/grafana/provider.go +++ b/grafana/provider.go @@ -28,6 +28,12 @@ func Provider() terraform.ResourceProvider { DefaultFunc: schema.EnvDefaultFunc("GRAFANA_AUTH", nil), Description: "Credentials for accessing the Grafana API.", }, + "org_id": { + Type: schema.TypeInt, + Required: true, + DefaultFunc: schema.EnvDefaultFunc("GRAFANA_ORG_ID", 1), + Description: "Organization id for resources", + }, }, ResourcesMap: map[string]*schema.Resource{ @@ -51,6 +57,7 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) { cli.Transport = logging.NewTransport("Grafana", cli.Transport) cfg := gapi.Config{ Client: cli, + OrgID: d.Get("org_id").(int64), } if len(auth) == 2 { cfg.BasicAuth = url.UserPassword(auth[0], auth[1]) diff --git a/grafana/provider_test.go b/grafana/provider_test.go index 9daba4c72..1152cf2ec 100644 --- a/grafana/provider_test.go +++ b/grafana/provider_test.go @@ -51,4 +51,7 @@ func testAccPreCheck(t *testing.T) { if v := os.Getenv("GRAFANA_AUTH"); v == "" { t.Fatal("GRAFANA_AUTH must be set for acceptance tests") } + if v := os.Getenv("GRAFANA_AUTH"); v == "" { + t.Fatal("GRAFANA_AUTH must be set for acceptance tests") + } } diff --git a/website/docs/index.html.markdown b/website/docs/index.html.markdown index 8f1c43100..68dc6dca6 100644 --- a/website/docs/index.html.markdown +++ b/website/docs/index.html.markdown @@ -22,14 +22,19 @@ The provider configuration block accepts the following arguments: are provided in a single string and separated by a colon. May alternatively be set via the ``GRAFANA_AUTH`` environment variable. +* org_id - (Required) The organization id to operate on within grafana. + Default org_id is 1. May alternatively be set via the + GRAFANA_ORG_ID environment variable. + Use the navigation to the left to read about the available resources. ## Example Usage ```hcl provider "grafana" { - url = "http://grafana.example.com/" - auth = "1234abcd" + url = "http://grafana.example.com/" + auth = "1234abcd" + org_id = 1 } resource "grafana_dashboard" "metrics" {