Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add organization id to the provider. #110

Merged
merged 4 commits into from
Dec 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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-20201026050958-d171908f4835
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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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-20201026050958-d171908f4835 h1:IdYj5SLuW3BuQfw3eyIlpB+IKeEgKa1Mmen9Hr521Sk=
github.com/grafana/grafana-api-golang-client v0.0.0-20201026050958-d171908f4835/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=
Expand Down
7 changes: 7 additions & 0 deletions grafana/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -52,6 +58,7 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
cli.Transport = logging.NewTransport("Grafana", cli.Transport)
cfg := gapi.Config{
Client: cli,
OrgID: int64(d.Get("org_id").(int)),
}
if len(auth) == 2 {
cfg.BasicAuth = url.UserPassword(auth[0], auth[1])
Expand Down
3 changes: 3 additions & 0 deletions grafana/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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_ORG_ID"); v == "" {
t.Fatal("GRAFANA_ORG_ID must be set for acceptance tests")
}
}
9 changes: 7 additions & 2 deletions website/docs/index.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down