-
Notifications
You must be signed in to change notification settings - Fork 236
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 Caching support to Datasources #765
Comments
I'd love to see this added to the provider as well. @julienduchesne Presumably this wouldn't be part of the data_source resource since enterprise features tend to be separate resources? Happy to help, but would like to understand first what the preferred approach would be! |
Seems like there's an API for it: https://grafana.com/docs/grafana/latest/developers/http_api/query_and_resource_caching/ Even though it's an enterprise feature, it's a 1:1 mapping with a datasource so I think it makes most sense to be in the datasource resource We could query it only in the presence of the caching block. Example: This doesn't query it:
While this will query it:
When the block is present, we query the API. All attributes from the API are resolved |
Hi @cindy , Now that the GO library supports it, any sight on when this will be added to Terraform? Really looking forward to using it (would save me from manually enabled caching all over the place 😛 |
@fatbasstard Thanks for the ping. I'll pick this back up 👍 |
Any progress on this one? I have been looking for this functionality. |
I was going to pick this up as it's also a feature I require however, I believe it is blocked by grafana/grafana#86453. The current iteration of the terraform provider only depends on https://github.com/grafana/grafana-openapi-client-go (and not https://github.com/grafana/grafana-api-golang-client) which does not include any methods to access the cache endpoints. This is due to the cache endpoints being missing from the OpenAPI spec being used to generate the client. |
Looks like your PR is merged. Are you still planning to push this one along @ImTomEddy? |
Unfortunately, I've not had the time since the team at Grafana were able to get this added to the OpenAPI spec. |
This would also be very handy for us! Now we have to manage caching manually |
Until supported by the Grafana provider, I've used Mastercard's generic restapi provider to manage data source cache, like so: terraform {
required_providers {
restapi = {
source = "mastercard/restapi"
version = "~> 1.20.0"
}
}
}
variable "grafana_url" {}
variable "datasource_uid" {}
variable "bearer_token" {}
provider "restapi" {
# https://registry.terraform.io/providers/Mastercard/restapi/latest/docs
uri = "${var.grafana_url}/api"
write_returns_object = true
headers = {
"Authorization" = "Bearer ${var.bearer_token}"
"Content-Type" = "application/json"
}
}
resource "restapi_object" "datasource_cache_config" {
# https://grafana.com/docs/grafana/latest/developers/http_api/query_and_resource_caching/
# https://editor.swagger.io/?url=https://raw.githubusercontent.com/grafana/grafana/main/public/openapi3.json
path = "/datasources/{id}/cache"
data = jsonencode({
enabled = true
})
id_attribute = "dataSourceUID"
object_id = var.datasource_uid
read_path = "/datasources/{id}/cache"
update_method = "POST"
update_path = "/datasources/{id}/cache"
destroy_method = "POST"
destroy_path = "/datasources/{id}/cache/disable"
}
output "api_response" {
value = jsondecode(restapi_object.datasource_cache_config.api_response)
} |
Hi,
Currently datasource caching (Documentation) is not supported by the Provider.
We're moving to Enterprise instances and would like to enable Caching using Terraform. Asked Grafana about provisioning option and got this reply:
So the API supports it, can this be added to the data_source resources?
The text was updated successfully, but these errors were encountered: