If you're a learning-by-doing kind of person, you can follow the steps below to build your own example.
First of all, you need to have these tools up and running before starting:
- Terraform
- Terraform Cloud (to store
.tfstate
files)- Alternatively, you can use any Remote State backend.
- Please, bear in mind that you should not store
.tfstate
files locally in your repository.
- Grafana Cloud instance (with a service account token with enough permissions - e.g. admin)
-
Create a
main.tf
file with a main definition:terraform { required_providers { schemas = { source = "grafana/schemas" version = "0.2.0" } grafana = { source = "grafana/grafana" version = "2.1.0" } } } provider "grafana" { url = var.GRAFANA_URL auth = var.GRAFANA_TOKEN }
-
Create a
vars.tf
file with the variables' definition (will be read from environment):variable "GRAFANA_URL" { type = string description = "Fully qualified domain name of your Grafana instance." } variable "GRAFANA_TOKEN" { type = string description = "Basic auth password or API token." }
-
Initialize a new Terraform working directory:
terraform init
-
Create a
resources.tf
file with a basic dashboard and the resource definition:data "schemas_core_dashboard" "example" { title = "Terraform example" description = "Example dashboard built with Terraform" } resource "grafana_dashboard" "example" { config_json = data.schemas_core_dashboard.example.rendered_json }
-
Set up Grafana and Terraform auth as Actions secrets:
GRAFANA_URL
with the root url of your instanceGRAFANA_TOKEN
with your service account tokenTF_API_TOKEN
with your Terraform Cloud API token
Additionally, you may want to set up the following variables:
TF_CLOUD_ORGANIZATION
with the id of your Terraform cloud organizationTF_WORKSPACE
with the id of your Terraform cloud workspace
Have you detected a typo or something incorrect, and you are willing to contribute?
Please, open a pull request, and I'll be happy to review it.