grafana / terraform-provider-grafana

Terraform Grafana provider
https://www.terraform.io/docs/providers/grafana/
Mozilla Public License 2.0
411 stars 219 forks source link

Alert Name not allow ":" since legacy ID format #1621

Closed nicolas-rey closed 3 weeks ago

nicolas-rey commented 1 month ago

Terraform Version

1.6.5

Terraform Grafana Provider Version

2.15 (and upper)

Grafana Version

10.2.5

Affected Resource(s)

Terraform Configuration Files

resource "grafana_folder" "grafana" {
  title = "Grafana"
}

resource "grafana_rule_group" "grafana_health" {
  name             = "testing:grafana:health"
  folder_uid       = grafana_folder.grafana.uid
  interval_seconds = 30

  rule {
    name      = "testing:grafana:health"
    condition = "B"

    data {
      ref_id = "A"

      relative_time_range {
        from = 300
        to   = 0
      }

      datasource_uid = "influxdb"
      model          = "{\"adhocFilters\":[],\"alias\":\"$col pods\",\"datasource\":{\"type\":\"influxdb\",\"uid\":\"influxdb\"},\"dimensions\":{},\"expression\":\"\",\"groupBy\":[{\"params\":[\"$__interval\"],\"type\":\"time\"},{\"params\":[\"0\"],\"type\":\"fill\"}],\"highResolution\":false,\"id\":\"\",\"intervalMs\":10000,\"limit\":\"\",\"maxDataPoints\":500,\"measurement\":\"kubernetes_deployment\",\"metricEditorMode\":0,\"metricName\":\"\",\"metricQueryType\":0,\"namespace\":\"\",\"orderByTime\":\"ASC\",\"period\":\"\",\"policy\":\"default\",\"query\":\"\",\"refId\":\"A\",\"region\":\"default\",\"resultFormat\":\"time_series\",\"returnData\":false,\"select\":[[{\"params\":[\"replicas_available\"],\"type\":\"field\"},{\"params\":[],\"type\":\"last\"},{\"params\":[\"*100 /(last(replicas_available)+last(replicas_unavailable))\"],\"type\":\"math\"},{\"params\":[\"grafana\"],\"type\":\"alias\"}]],\"slimit\":\"\",\"statistic\":\"Average\",\"tags\":[{\"key\":\"deployment_name::tag\",\"operator\":\"=~\",\"value\":\"/^grafana$/\"}],\"tz\":\"\"}"
    }
    data {
      ref_id = "B"

      relative_time_range {
        from = 600
        to   = 0
      }

      datasource_uid = "__expr__"
      model          = "{\"conditions\":[{\"evaluator\":{\"params\":[75,0],\"type\":\"lt\"},\"operator\":{\"type\":\"and\"},\"query\":{\"params\":[\"A\"]},\"reducer\":{\"params\":[],\"type\":\"avg\"},\"type\":\"query\"},{\"evaluator\":{\"params\":[0,0],\"type\":\"no_value\"},\"operator\":{\"type\":\"or\"},\"query\":{\"params\":[\"A\"]},\"reducer\":{\"params\":[],\"type\":\"avg\"},\"type\":\"query\"}],\"datasource\":{\"name\":\"Expression\",\"type\":\"__expr__\",\"uid\":\"__expr__\"},\"expression\":\"\",\"intervalMs\":1000,\"maxDataPoints\":43200,\"refId\":\"B\",\"type\":\"classic_conditions\"}"
    }

    no_data_state  = "Alerting"
    exec_err_state = "OK"
    for            = "8m"
    annotations = {
      summary = "Health of grafana"
    }
    labels = {
      environment = "testing"
      perimeter   = "grafana"
      services    = "grafana"
    }
    is_paused = false
  }
}

Expected Behavior

This HCL need to create an alert with title "testing:grafana:health" on the folder uid linked to grafana_folder.grafana.uid (for exemple ee1ee37a-79e2-4ecb-8ab0-01266d403b63) With the grafana provider 2.15.0 and upper, the id for this alerta will be "ee1ee37a-79e2-4ecb-8ab0-01266d403b63:testing:grafana:health" (with the Legacy ID)

Actual Behavior

When apply this job resultat is an error of format. Grafana provider not match the format "folderUID:title" because the title of the rule contains some ":".

image

Before the legacy ID format, if the split on ";" was give more that 2 elements the first was for the folder id and all others were concat with ";" for the title. Since the #1453, split is on ":", if result have more of 2 elements are on the table, the first is for the folder uid but all other isn't concat after get the uid folder.

Steps to Reproduce

  1. terraform apply

Important Factoids

No response

References

rafaelleonelpontani-gurumatch commented 1 month ago

I am having the same problem. What information should I provide to help? image

julienduchesne commented 1 month ago

👍 I will take a look today

rafaelleonelpontani-gurumatch commented 3 weeks ago

Hello @julienduchesne , can you suggest a workaround?

julienduchesne commented 3 weeks ago

Unfortunately can't but this will be fixed in the next version (probably tomorrow)

julienduchesne commented 3 weeks ago

Should be fixed in v2 and v3