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

Grafana Dashboard doesn't support folder_id and org_id #31

Closed
fotto1 opened this issue Aug 21, 2018 · 5 comments
Closed

Grafana Dashboard doesn't support folder_id and org_id #31

fotto1 opened this issue Aug 21, 2018 · 5 comments

Comments

@fotto1
Copy link

fotto1 commented Aug 21, 2018

Terraform Version

Terraform v0.11.2

  • provider.grafana v1.0.2

Affected Resource(s)

  • grafana_dashboard

Terraform Configuration Files

provider "grafana" {
}

data "template_file" "helloworld" {


  template = "${file("${path.module}/helloworld.json")}"

  vars {
    dashboard_name = "hello_world"
  }

}

resource "grafana_dashboard" "helloworld" {
  config_json = "${data.template_file.helloworld.rendered}"
  org_id = 1
  folder_id = axS1XHVmk
}

The code is working and the grafana dashboard will be created. But in wrong Grafana Organization and Folder because I'm not able to set following parameters:

  • org_id - ID of the Organisation in Grafana
  • folder_id - ID of Folder in Grafana Organization

I use a grafana version 5.2.1 (2040f61)

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. create a provider with Grafana and credentials
  2. terraform apply
@erothmayer
Copy link
Contributor

Digging around in the code today, it looks like someone added folder to grafana_dashboard recently. My PR above adds docs describing that feature.

@scsinutz
Copy link

scsinutz commented Nov 20, 2018

Also, there doesn't seem to be a way to associate a datasource to a ORG_ID

@bcampoli
Copy link

bcampoli commented May 9, 2019

Hey guys, after a lot of digging around I figured out a way to add ORG_ID to all resources in Graphana, and hence associate them with a particular org. The root of the issue lies in how the Graphana API deals with Orgs. When you call the Graphana API to create/retrieve/update/delete a resource the API call is always associated with the "current org". No idea why they decided to do this but this totally breaks the "RESTful" standard of API calls being stateless and self contained. Here is the desired behavior, which I have been able to implement:

provider "grafana" {
  url  = "http://localhost:3000/"
  auth = "admin:admin"
}


resource "grafana_organization" "org1" {
  name         = "test-provider1"
  admin_user   = "admin"
}

resource "grafana_organization" "org2" {
  name         = "test-provider2"
  admin_user   = "admin"
}

resource "grafana_data_source" "metrics" {
  type          = "graphite"
  name          = "myapp-metrics-test"
  org_id        = "${grafana_organization.org1.id}"  
}

resource "grafana_data_source" "metrics2" {
  type          = "graphite"
  name          = "myapp-metrics-test2"
  org_id        = "${grafana_organization.org2.id}"  
}

resource "grafana_data_source" "metrics3" {
  type          = "graphite"
  name          = "myapp-metrics-test3"
  org_id        = "${grafana_organization.org1.id}"  
}

resource "grafana_data_source" "metrics4" {
  type          = "graphite"
  name          = "myapp-metrics-test4"
  org_id        = "${grafana_organization.org2.id}"  
}

How this is possible:

Deep, hidden in the Graphana issues page, you find an undocumented header that can be used to specify which org you would like to attach a particular resource to. The header: X-Grafana-Org-Id. So in setting this header with your API request, you can specify which org you want to associate a particular resource with. So as you can imagine, in order to use this header, it is required to also modify the graphana client library that is making the API calls on behalf of this provider. So I did this and added the ability to add this header with all the API calls.

After modifying the client library, I was able to change the graphana provider and add an org_id field to all of the resources. So the above behaviour can now be accomplished.

I would like to get this implemented into the main repo, but seeing as I also modified the client library, I would like some info on what the best approach is.

Here is my modified graphana provider: https://github.com/emerald-squad/terraform-provider-grafana
and the modified client library it is using: https://github.com/emerald-squad/go-grafana-api

@bcampoli
Copy link

See pull request https://github.com/terraform-providers/terraform-provider-grafana/pull/60 which partially addresses this issue.

@julienduchesne
Copy link
Member

folder is supported in the dashboard but org_id will not be added. See #59 (comment) for the reasoning (and an example on how to associate resources to an org)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants