The provider offers a handy syntax to define Grafana dashboards: time series, gauge, bar gauge, stat, etc.
Please, see provider documentation.
The provider defines only data sources. Each data source computes a JSON that is compatible with Grafana API. Therefore, this provider is not particularly useful on its own, but it can be used to generate a JSON compatible with Grafana API, which can then be used with Grafana provider to provision a dashboard.
data "gdashboard_stat" "status" {
title = "Status"
description = "Shows the status of the container"
field {
mappings {
value {
value = "1"
display_text = "UP"
color = "green"
}
special {
match = "null+nan"
display_text = "DOWN"
color = "red"
}
}
}
queries {
prometheus {
uid = "prometheus"
expr = "up{container_name='container'}"
instant = true
}
}
}
data "gdashboard_dashboard" "dashboard" {
title = "My dashboard"
layout {
section {
title = "Basic Details"
panel {
size = {
height = 8
width = 10
}
source = data.gdashboard_stat.status.json
}
}
}
}
# Define provider
provider "grafana" {
url = "https://my.grafana.com" # use your API endpoint
auth = var.grafana_auth
}
# Create your dashboard
resource "grafana_dashboard" "my_dashboard" {
config_json = data.gdashboard_dashboard.dashboard.json
}- Clone the repository
- Enter the repository directory
- Build the provider using the Go
installcommand:
go installThis provider uses Go modules. Please see the Go documentation for the most up-to-date information about using Go modules.
To add a new dependency github.com/author/dependency to your Terraform provider:
go get github.com/author/dependency
go mod tidyThen commit the changes to go.mod and go.sum.
If you wish to work on the provider, you'll first need Go installed on your machine (see Requirements above).
To compile the provider, run go install. This will build the provider and put the provider binary in the $GOPATH/bin directory.
To generate or update documentation, run go generate.
In order to run the full suite of Acceptance tests, run make testacc.
Note: Acceptance tests create real resources, and often cost money to run.
make testaccBuild the provider locally:
$ go build -o terraform-provider-gdashboardAdd a path to the folder with the binary to the dev.tfrc:
provider_installation {
dev_overrides {
"gdashboard/gdashboard" = "../terraform-provider-gdashboard"
}
direct {}
}Configure terraform cli:
$ export TF_CLI_CONFIG_FILE=./dev.tfrcRun changes:
$ terraform plan