-
Notifications
You must be signed in to change notification settings - Fork 229
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
Added ability to specify org_id field in resource definitions #60
Conversation
Switch context
added org_id field
Any plans to get this merged any time soon? |
this is really a good fix, when could the pr be accepted? |
I would also greatly appreciate having this merged. Is there anything I can do to help? |
Status on getting this merged? This is a pretty crucial function of Grafana in many environments |
@@ -2,8 +2,8 @@ module github.com/terraform-providers/terraform-provider-grafana | |||
|
|||
require ( | |||
github.com/blang/semver v3.5.1+incompatible // indirect | |||
github.com/emerald-squad/go-grafana-api v0.0.0-20190510131408-a95b9575e28e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please open a PR of the required changes to support orgs to the upstream library?
We will review the changes necessary there and then come back to the changes here.
@bcampoli Looks like this could use a rebase. I'm looking very much forward to having this merged 🙏 |
Happy to help as needed, let me know what needs to be done to get this merged into master. This would help immensely with managing all our orgs correctly instead of custom scripts we use today |
Any update on this PR? |
We're also waiting for this... @mlclmj any chance please? |
Closing in favor of #110 and grafana/grafana-api-golang-client#9. |
@trotttrotttrott it's good but with terraform we can dynamically provision organisations, we cant dymanically loop through providers. example below locals {
orgs = {
Main = {
admin_user = "admin"
create_users = false
admins = []
editors = []
viewers = []
}
NewOrg = {
admin_user = "admin"
create_users = true
admins = []
editors = []
viewers = []
}
}
}
resource "grafana_organization" "this" {
for_each = local.orgs
name = each.key
admin_user = each.value.admin_user
create_users = each.value.create_users
admins = each.value.admins
editors = each.value.editors
viewers = each.value.viewers
} then data source example locals {
data_sources = {
test-dsource = {
org = "NewOrg"
type = "mssql"
url = "blah.example.com:1433"
database_name = "my_db"
username = "my_user"
password = "noidea"
}
}
}
resource "grafana_data_source" "this" {
for_each = local.data_sources
org_id = grafana_organization.this[each.value.org].id
name = each.key
type = each.value.type
url = each.value.url
database_name = try(each.value.database_name, null)
username = try(each.value.username, null)
password = try(each.value.password, null)
} this wont be possible provider "grafana" {
for_each = local.grafana_providers
alias = each.key
}
```hcl |
Hi guys, here I present to you a pretty significant pull request, which adds the basic functionality to specify the org with which you would like to associate a resource with.
This is a crucial feature since internally, each Grafana API object is implicitly linked to an
org_id
. Therefore, in order to align the Terraform Provider with the data-model used by Grafana, the resources should also have anorg_id
field.This is very cool because now you can use Terraform to manage the multi-tenancy within Grafana!
Affected Resource(s):
Please list the resources as a list, for example:
grafana_organization
Example:
For example, given the sample configuration (the below example is using just
grafana_data_source
):We observe the following behavior:
and
The above is just an example for
grafana_data_source
but this change now applies to all resources in the provider including dashboards, folders, and notifications.How?
By adding the following header to API calls:
X-Grafana-Org-Id
(https://community.grafana.com/t/organization-state-in-the-api/7954), one can specify the org they want the API call to be associated with. This allows for a more RESTful API (even though technically it is not). In order to add this header, I had to also modify the client library that this provider was relying on: (https://github.com/emerald-squad/go-grafana-api).Since this is a new
required
field, I have had to modify the acceptance tests to add and check for the org_id field.Related issues:
https://github.com/terraform-providers/terraform-provider-grafana/issues/59
https://github.com/terraform-providers/terraform-provider-grafana/issues/31