Skip to content
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 datasource with terraform #70

Open
M4vish opened this issue Mar 13, 2023 · 1 comment
Open

add datasource with terraform #70

M4vish opened this issue Mar 13, 2023 · 1 comment

Comments

@M4vish
Copy link

M4vish commented Mar 13, 2023

Hi all,

I'm trying to add the grafana mqtt data source with terraform in a k3s cluster but unfortunately it does not work.
The "grafana-mqtt-datasource" is installed successfully and I'm able to add a new datasource with the webfrontend, but not with the terraform scripts.
I tried different settings for the "datasource type" e.g. MQTT, mqtt, Mqtt but without any success.
Attached some snippets.

template "grafana-values.tpl":

# https://github.com/grafana/helm-charts/blob/main/charts/grafana/values.yaml
admin:
  existingSecret: "${GRAFANA_SECRET}"
  userKey: GRAFANA_USERNAME
  passwordKey: GRAFANA_PASSWORD

envFromSecret: "${GRAFANA_SECRET}"

plugins:
  - grafana-mqtt-datasource

datasources:
  datasources.yaml:
    apiVersion: 1
    datasources:
    - name: ${VO_DATASOURCE_NAME}
      type: mqtt
      uri: ws://${MQTT_SERVICE_NAME}.${BROKER_NAMESPACE}:${MQTT_PORT}
      Username: ${MQTT_USERNAME}
      Password: ${MQTT_PASSWORD}
      isDefault: true
      editable: true

main.tf

resource "kubernetes_secret" "grafana-secret" {
  metadata {
    name      = var.secret
    namespace = var.namespace
  }
  data = {
    GRAFANA_USERNAME    = var.username
    GRAFANA_PASSWORD    = var.password
  }
  type = "Opaque"
}

# https://github.com/grafana/helm-charts/tree/main/charts/grafana
resource "helm_release" "grafana" {
  name        = var.name
  repository  = var.repository
  chart       = var.chart
  version     = var.chartversion
  namespace   = var.namespace

  values = [templatefile("${path.module}/grafana-values.tpl", {
    GRAFANA_PORT_NAME   = var.port_name
    GRAFANA_SECRET      = var.secret
    VO_DATASOURCE_NAME  = var.datasource_name
    MQTT_SERVICE_NAME   = var.mqtt_service_name
    BROKER_NAMESPACE    = var.broker_namespace
    MQTT_PORT           = var.mqtt_websocket_port
    MQTT_USERNAME       = var.mqtt_username
    MQTT_PASSWORD       = var.mqtt_password
  })]
}

The Script is working, the datasources.yml is created successfully with the correct YAML syntax and in the webfrontend you'll see the mqtt Datasource. But when you click on it, it says "Plugin not found, no installed plugin with that id".
But again, if you add the mqtt datasource by hand, it works as it should.
Thx in advance.

@deviantony
Copy link

@M4vish I managed to make Grafana use a datasource with this plugin at boot time, you can use the following configuration as a reference:

apiVersion: 1

datasources:
  - name: MQ-data
    type: grafana-mqtt-datasource
    version: 1
    editable: true
    isDefault: false
    jsonData:
      uri: tcp://broker:1883
      username: ${MQTT_USERNAME} 
    secureJsonData:
      password: ${MQTT_PASSWORD}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants