Skip to content

Commit 6b49cca

Browse files
committed
Add organization id to the provider.
Use the change in nytm/go-grafana-api#62 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" } ```
1 parent c9213b9 commit 6b49cca

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

grafana/provider.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ func Provider() terraform.ResourceProvider {
2424
DefaultFunc: schema.EnvDefaultFunc("GRAFANA_AUTH", nil),
2525
Description: "Credentials for accessing the Grafana API.",
2626
},
27+
"org_id": {
28+
Type: schema.TypeInt,
29+
Required: true,
30+
DefaultFunc: schema.EnvDefaultFunc("GRAFANA_ORG_ID", 1),
31+
Description: "Organization id for resources",
32+
},
2733
},
2834

2935
ResourcesMap: map[string]*schema.Resource{
@@ -42,6 +48,7 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
4248
client, err := gapi.New(
4349
d.Get("auth").(string),
4450
d.Get("url").(string),
51+
d.Get("org_id").(int),
4552
)
4653
if err != nil {
4754
return nil, err

website/docs/index.html.markdown

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ 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
@@ -30,6 +34,7 @@ Use the navigation to the left to read about the available resources.
3034
provider "grafana" {
3135
url = "http://grafana.example.com/"
3236
auth = "1234abcd"
37+
org_id = 1
3338
}
3439
3540
resource "grafana_dashboard" "metrics" {

0 commit comments

Comments
 (0)