TorraformによるGrafanaマルチテナント構成


Grafanaのマルチテナント環境を設定する方法は、各テナントを分割する組織を使用することです.しかし、どのようにIACでこれを設定できますか?
Grafanaは設定ファイルを使用するアクティブなプロビジョニングシステムを提供します.データソースとダッシュボードは、バージョン管理されるファイルを通して定義されることができます.
これらの設定ファイルを管理する多くのツールがあります.
  • Puppet
  • Ansible
  • Chef
  • Saltstack
  • Jsonnet
  • Grafanaプロビジョニングは、データソース、プラグイン、ダッシュボードとアラート通知チャネルの構成を可能にします.これらの“オブジェクト”のすべては、特定の組織で作成することができます.

    This is great, what else would you like?
    I would like a little bit more. What happens with the organization or the users? Can I configure them by IaC?
    Yes, you can, and Terraform is going to help with that.



    グラファナプロバイダー
    グラファナはofficial Terraform provider にはusers and organizations .

    マルチテナント構成
    Torraformと異なる組織のリソースを管理するためには、組織IDを持つGrafanaのプロバイダを設定しなければなりません.
    例えば、
    provider "grafana" {
      url  = "http://127.0.0.1:3000"
      auth = "admin:admin"
      org_id = 1
    }
    
    だから、アイデアは2つの異なるプロバイダを使用しているalias . 最初に、組織管理者ユーザーと管理者ユーザーを作成します.そして、第2は、前のステップでつくられる組織とユーザーを使います.
    例:
    provider "grafana" {
      url  = "http://127.0.0.1:3000"
      auth = "admin:admin"
      alias = "admin"
    }
    provider "grafana" {
      url  = "http://127.0.0.1:3000"
      auth = "admin_org_2:pass_org_2"
      org_id = 2
      alias = "config"
    }
    

    完全な例
    十分な理論は、実用的な例を取りましょう.必要な場合は
  • Terraform
  • Kind
  • このリポジトリのクローン化https://github.com/jilgue/medium-grafana-multi-tenant

  • Kubie (必要)
  • KubernetesクラスタにGrafanaを配備する
    $ kind create cluster
    $ kubie ctx kind-kind
    $ cd 010-environment/010-grafana
    $ terraform init
    $ terraform apply
    $ terraform output admin_password
    $ kubectl port-forward service/grafana 3000
    
    私たちのGrafanaはhttp://127.0.0.1:3000 . 管理者のユーザとリソースを使って新しい組織を作りましょう
    $ cd ../../020-client-1/010-grafana-config/
    $ terraform init
    $ terraform apply
    $ terraform output password
    
    現在管理者またはクライアント1でログインして、組織を切り換えて、我々はフォルダがつくられるのを見ます.
    http://localhost:3000/dashboards?orgId=2