You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
locals {
authorization_base64 = base64encode("${var.GRAFANA_ADAPTIVE_METRICS_TENANT}:${var.GRAFANA_ADAPTIVE_METRICS_TOKEN}")
}
# In order to "Upload new aggregation rules" we need to follow two step process described here
# https://grafana.com/docs/grafana-cloud/account-management/billing-and-usage/control-metrics-usage-via-adaptive-metrics/#upload-new-aggregation-rules
# There special header Etag that we need to get from previous upload and put value from it in header If-Match
data "http" "current_adaptive_metrics_aggregation_rules" {
url = "${var.GRAFANA_ADAPTIVE_METRICS_URL}/aggregations/rules"
method = "GET"
# Optional request headers
request_headers = {
Accept = "application/json"
Authorization = "Basic ${local.authorization_base64}"
}
}
data "http" "new_adaptive_metrics_aggregation_rules" {
url = "${var.GRAFANA_ADAPTIVE_METRICS_URL}/aggregations/rules"
method = "POST"
# Optional request headers
request_headers = {
Accept = "application/json"
Authorization = "Basic ${local.authorization_base64}"
If-Match = data.http.current_adaptive_metrics_aggregation_rules.response_headers.Etag
}
request_body = var.grafana_adaptive_metrics_recommendations
}
# Inspired by https://registry.terraform.io/providers/hashicorp/http/latest/docs/data-sources/http#usage-with-provisioner
resource "null_resource" "new_adaptive_metrics_aggregation_rules_check" {
# On success, this will attempt to execute the true command in the
# shell environment running terraform.
# On failure, this will attempt to execute the false command in the
# shell environment running terraform.
provisioner "local-exec" {
command = contains([200], data.http.new_adaptive_metrics_aggregation_rules.status_code)
}
}
This solution is the hack that applies during plan phase instead of apply.
The text was updated successfully, but these errors were encountered:
Thanks for this workaround @Hronom. I suspect we're going to run head first into this as well, we try to manage a subset of Grafana using IAC and this certainly looks to fall under that subset. local-exec provisioners do make me cringe a bit whenever I have to use them - would be lovely to have a well-trodden path built into the provider for this.
Need support for Adaptive Metrics in terraform.
Here is the current workaround that I use:
This solution is the hack that applies during plan phase instead of apply.
The text was updated successfully, but these errors were encountered: