Skip to content

Commit

Permalink
Add organization id to the provider.
Browse files Browse the repository at this point in the history
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"
}
```

Co-authored-by: hansnqyr <[email protected]>
  • Loading branch information
medains and hansnqyr committed Aug 5, 2020
1 parent c9213b9 commit bbe87e2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
7 changes: 7 additions & 0 deletions grafana/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,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 @@ -42,6 +48,7 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
client, err := gapi.New(
d.Get("auth").(string),
d.Get("url").(string),
d.Get("org_id").(int),
)
if err != nil {
return nil, err
Expand Down
5 changes: 5 additions & 0 deletions website/docs/index.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ 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
Expand All @@ -30,6 +34,7 @@ Use the navigation to the left to read about the available resources.
provider "grafana" {
url = "http://grafana.example.com/"
auth = "1234abcd"
org_id = 1
}
resource "grafana_dashboard" "metrics" {
Expand Down

0 comments on commit bbe87e2

Please sign in to comment.