grafana_data_source_config (Resource)

The required arguments for this resource vary depending on the type of data source selected (via the 'type' argument).

Use this resource for configuring multiple datasources, when that configuration (json_data_encoded field) requires circular references like in the example below.

When using the grafana_data_source_config resource, the corresponding grafana_data_source resources must have the json_data_encoded and http_headers fields ignored. Otherwise, an infinite update loop will occur. See the example below.

Example Usage

resource "grafana_data_source" "loki" {
  type = "loki"
  name = "loki"
  url  = "http://localhost:3100"

  lifecycle {
    ignore_changes = [json_data_encoded, http_headers]
  }
}

resource "grafana_data_source" "tempo" {
  type = "tempo"
  name = "tempo"
  url  = "http://localhost:3200"

  lifecycle {
    ignore_changes = [json_data_encoded, http_headers]
  }
}

resource "grafana_data_source_config" "loki" {
  uid = grafana_data_source.loki.uid

  json_data_encoded = jsonencode({
    derivedFields = [
      {
        datasourceUid = grafana_data_source.tempo.uid
        matcherRegex  = "[tT]race_?[iI][dD]\"?[:=]\"?(\\w+)"
        matcherType   = "regex"
        name          = "traceID"
        url           = "$${__value.raw}"
      }
    ]
  })
}

resource "grafana_data_source_config" "tempo" {
  uid = grafana_data_source.tempo.uid

  json_data_encoded = jsonencode({
    tracesToLogsV2 = {
      customQuery     = true
      datasourceUid   = grafana_data_source.loki.uid
      filterBySpanID  = false
      filterByTraceID = false
      query           = "|=\"$${__trace.traceId}\" | json"
    }
  })
}

Schema

Optional

Read-Only

Import

Import is supported using the following syntax:

terraform import grafana_data_source_config.name "{{ uid }}"
terraform import grafana_data_source_config.name "{{ orgID }}:{{ uid }}"