-
Notifications
You must be signed in to change notification settings - Fork 218
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 support to provide the input variables for dashboards #1040
Comments
Terraform v1.9.0 has a templatestring function (https://discuss.hashicorp.com/t/experiment-feedback-the-templatestring-function/66645). It would look something like:
Does that work? |
The other option is to use the external provider: https://registry.terraform.io/providers/hashicorp/external/latest/docs/data-sources/external. Write a tiny script that does the templating Having two fields managing the JSON config of a dashboard is not going to give you a great experience. Terraform providers work well with a 1:1 field mapping. Next steps:If I were to implement something to complete this issue, it'd be a new datasource that, when given a dashboard JSON, it does some templating on it and spits it back out
Doing this has the following benefits:
Anyone has any opinions on this proposal? |
I would appreciate such a feature greatly! In addition to the possibility of overriding datasources what I would also like to see would be the option to inject / override dashboard settings such as UID, Tags and Links inside the config_json. |
🤔 hmm found this answer: https://stackoverflow.com/a/67378512 and I'm wondering if anyone has any dashboard mutations they want to do that aren't just search and replace. I feel like if it's possible to do with native Terraform, it doesn't deserve a new grafana specific datasource |
I didnt want to use (note: this is using Cloud Posse's null-label context for tf vars
{
"config_input": {
"${DS_PROMETHEUS}": "myuniqueprometheusid"
},
"dashboard_url": "https://grafana.com/api/dashboards/315/revisions/3/download",
} # variables.tf
variable "dashboard_url" {
type = string
description = "The marketplace URL of the dashboard to be created"
}
variable "additional_config" {
type = map(any)
description = "Additional dashboard configuration to be merged with the provided dashboard JSON"
default = {}
}
variable "config_input" {
type = map(string)
description = "A map of string replacements used to supply input for the dashboard config JSON"
default = {}
} # main.tf
locals {
enabled = module.this.enabled
# Replace each of the keys in var.config_input with the given value in the module.config_json[0].merged result
config_json = join("", [for k in keys(var.config_input) : replace(jsonencode(module.config_json[0].merged), k, var.config_input[k])])
}
data "http" "grafana_dashboard_json" {
count = local.enabled ? 1 : 0
url = var.dashboard_url
}
module "config_json" {
source = "cloudposse/config/yaml//modules/deepmerge"
version = "1.0.2"
count = local.enabled ? 1 : 0
maps = [
jsondecode(data.http.grafana_dashboard_json[0].response_body),
{
"uid" : module.this.id
"title" : module.this.id
},
var.additional_config
]
}
resource "grafana_dashboard" "this" {
count = local.enabled ? 1 : 0
config_json = local.config_json
} |
Currently the grafana_dashboard resource does not allow to provide the input values for the dashboards.
Currently I implemented a workaround.
This is how I'm currently working around the issue for a provisioning dashboards using the Terraform Grafana provider.
It would be great if the resource itself would allow providing these inputs.
e.g.
The text was updated successfully, but these errors were encountered: