Skip to content

Commit

Permalink
Add support for turning on caching by default for Athena data sources
Browse files Browse the repository at this point in the history
  • Loading branch information
avnes committed Nov 13, 2024
1 parent 091e1c4 commit 0ddb24b
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
19 changes: 19 additions & 0 deletions grafana_data_source_athena/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,22 @@ resource "grafana_data_source" "athena" {
workgroup = each.value.workgroup
})
}

# trunk-ignore(tflint/terraform_unused_declarations)
data "http" "enable_caching" {
for_each = var.enable_caching && var.grafana_url != "" && var.bearer_token != "" ? grafana_data_source.athena : {}
url = "${var.grafana_url}/api/datasources/${grafana_data_source.athena[each.key].uid}/cache/enable"
method = "POST"

request_headers = {
Accept = "application/json"
Authorization = "Bearer ${var.bearer_token}"
}

lifecycle {
postcondition {
condition = contains([200, 201, 204], self.status_code)
error_message = "Status code invalid for enabling caching for Athena data source"
}
}
}
19 changes: 19 additions & 0 deletions grafana_data_source_athena/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,22 @@ variable "data_sources" {
description = "Path to the json files with data sources"
type = list(string)
}

variable "enable_caching" {
description = "Enable caching for the data source"
type = bool
default = true
}

variable "grafana_url" {
description = "URL of the Grafana instance"
type = string
default = ""
}

variable "bearer_token" {
description = "Bearer token for the Grafana API"
sensitive = true
type = string
default = ""
}
4 changes: 4 additions & 0 deletions grafana_data_source_athena/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,9 @@ terraform {
source = "grafana/grafana"
version = ">= 2.9.0"
}
http = {
source = "hashicorp/http"
version = ">= 2.9.0"
}
}
}
4 changes: 4 additions & 0 deletions grafana_data_source_athena/versions.tofu
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,9 @@ terraform {
source = "grafana/grafana"
version = ">= 2.9.0"
}
http = {
source = "hashicorp/http"
version = ">= 2.9.0"
}
}
}

0 comments on commit 0ddb24b

Please sign in to comment.