Git Product home page Git Product logo

opentofu-grafana-example's Introduction


OpenTofu (open-source Terraform fork) + Grafana: Example tutorial

Static Badge Static Badge

Learn by doing. Create a datasource, a folder and import dahsboards in it with panels using this datasource. You can copy this and customize it to make much more using the Grafana provider.

Create a Grafana Cloud stack

Create a Grafana Cloud Free account. No credit card required.

Create a free account


Set your OpenTofu

You can set OpenTofu the way you want. If you never did that, here are the steps you can follow:

  1. Install OpenTofu using the official documentation for your environment.
  2. Initialize OpenTofu by running tofu init

Create a Service Account token for your Grafana

  1. Go to the Service Account page: go to your Grafana instance, open the menu and click on Administration > Services Account
  2. Create a new Service Account with permissions on folders, datasources, alerts and dashboards
  3. Create a new token for this Service Account. As best practice, use an expiration date. Copy the token, it is not possible to display it later.

Deploy to your Grafana

We will deploy:

  • A folder
  • A datasource (we use Test Data, ensure it's installed on your Grafana)
  • A dashboard
  • An alert

To do that, use the following command:

tofu apply -var 'grafana_url=<CHANGE ME>' -var 'my_token=<CHANGE ME>' -var 'my_email=<CHANGE ME>'

OpenTofu will ask you to confirm. Type yes.

Replace the values for grafana_url and my_token with the right values for your environment:

  • grafana_url should look like https://mystack.grafana.net/ in Grafana Cloud (or other domains if you use OSS or Enterprise)
  • my_token is the API token you created
  • my_email is the email address to receive alerts (don't worry, the alert rule never fires in this example)

You can now visit your instance and check that the folder, dashboard, and alerts are present.

You may found no data in your dashboard when opening it. You need to reload the page as your browser cache prevents the webapp to use the new datasource.

Cleanup your environment

As Code is great because cleaning up your tests are also very fast !

With the same values, run:

tofu destroy -var 'grafana_url=<CHANGE ME>' -var 'my_token=<CHANGE ME>'

To fully cleanup the environment, you can also remove the Service Account you created manually.


Acknowledgments

Some useful ressources from Grafana Labs and friends:

(back to top)

opentofu-grafana-example's People

Contributors

clementduveau avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

yamikarajput546

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.