Search code examples
grafanakubernetes-helm

How can I import users and teams to grafana?


I am provisioning grafana and running it without a database. I am using Terraform and Helm to do this. I already know that I can store my dashboard files, put them in the values.yaml file for the grafana helm chart, and provision them that way.

It's good that the dashboards persist between releases, but users and teams do not. I cannot find where I can upload or store some sort of JSON file containing this information.

For more information, I am using Google Oauth.

How can I provision users and teams' information? This does not have to be helm specific. If it's some sort of volume-mount thing, that would work too.


Solution

  • We just use the Grafana API via Ansible (using uri module), maybe it helps you or pushes you in the right direction.

    - name: create users
      uri:
        url: "https://{{ grafana_url }}/api/admin/users"
        user: admin
        password: "{{ admin_password }}"
        force_basic_auth: yes
        method: POST
        headers:
          Accept: application/json
          Content-Type: application/json
        body:
          name: "{{ item.name }}"
          email: "{{ item.email }}"
          login: "{{ item.email }}"
          password: "{{ pass }}"
        body_format: json
      with_items: "{{ admin_list }}"
    

    Then the list is a simple yaml.

    admin_list:
      - name: "Mrs. X"
        login: "[email protected]"
      - name: "Ms. Y"
        login: "[email protected]"
    

    And on a second note, you can define users in Terraform (never used it myself).

    resource "grafana_organization" "org" {
        name         = "Grafana Organization"
        admin_user   = "admin"
        create_users = true
        admins       = [
            "[email protected]"
        ]
        editors      = [
            "[email protected]",
            "[email protected]"
        ]
        viewers      = [
            "[email protected]",
            "[email protected]"
        ]
    }