Wavefront as Code using Terraform Integration — Part II

Sanooj Mananghat
4 min readMar 27, 2019

--

Dashboards - everything in one place, provides at-a-glance views of what is important to you, data as you want and look like you like.

Wavefront provides a data visualization solution that can transform your data into interactive, real-time and elegant dashboards.

In the previous article, we saw how to create Wavefront alerts as code using Terraform. In this article, we will go through how we can create Wavefront “Dashboards” with Terraform.

How to setup?

Initial Terraform setup is explained in the previous article which will result in the following directory structure.

wavefront_alerts/
├── main.tf
└── terraform.d
└── plugins
└── darwin_amd64
└── terraform-provider-wavefront_v1.1.0

While creating a dashboard in Wavefront, you will be asked to provide a unique “URL” and a “Name” for the dashboard.

A Wavefront Dashboard has few major components. Parameters, one or more Sections, each Section will have one or more Rows and each row can have one or more Charts.

Create a “main.tf” file with the Provider and Dashboard definition which includes the above components.

provider "wavefront" {
address = "longboard.wavefront.com"
token = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}
resource "wavefront_dashboard" "test_dashboard" {
name = "Terraform Dashboard Test"
description = "testing, testing"
url = "tftest"
#[PARAMETER START]
parameter_details {
name = "param1"
label = "param1"
default_value = "Label"
hide_from_view = false
parameter_type = "SIMPLE"
values_to_readable_strings = {
Label = "test"
}
}
#[PARAMETER END]
#[SECTION STARTS]
section {
name = "section 1"
#[ROW STARTS]
row {
#[CHART STARTS]
chart {
name = "chart 1"
description = "chart number 1"
units = "something per unit"
source {
name = "source name"
query = "ts(~http.api.extlink.simple.GET.200.count)"
}
chart_setting {
type = "line"
}
summarization = "MEAN"
}
#[CHART ENDS]
}
#[ROW ENDS]
}
#[SECTION ENDS]
tags = [
"terraform",
"test"
]
}

In the above terraform script, we have a provider definition and “wavefront_dashboard” resource definition.

Under “wavefront_dashboard” resource definition, we have “name” and “URL” which should be unique. After which we have defined the “Parameters” (named “param1” and value as “test”) followed by the “Section” (named “section 1”). Under this “Section”, we have defined one “Row” and one “Chart” in that Row.

NOTE: You can export the address and token as an environment variable to avoid committing them to Source Control (Highly recommended).

Run terraform to apply the changes.

terraform init
terraform apply

Which will create a Dashboard named “Terraform Dashboard Test”

Snapshot of the Dashboard

In order to add more Parameters, Sections, Rows and Charts to the Dashboard, repeat the corresponding block (Ex: to add a new Section, repeat the block between #[SECTION STARTS] … #[SECTION ENDS] as marked in the “main.tf” file.).

Here is an example, In “main.tf”, let’s duplicate “Parameters” and “Charts” and add a new Parameter and a Chart.

provider "wavefront" {
address = "longboard.wavefront.com"
token = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}
resource "wavefront_dashboard" "test_dashboard" {
name = "Terraform Dashboard Test"
description = "testing, testing"
url = "tftest"
#[PARAMETER START]
parameter_details {
name = "param1"
label = "param1"
default_value = "Label"
hide_from_view = false
parameter_type = "SIMPLE"
values_to_readable_strings = {
Label = "test1"
}
}
parameter_details {
name = "param2"
label = "param2"
default_value = "Label"
hide_from_view = false
parameter_type = "SIMPLE"
values_to_readable_strings = {
Label = "test2"
}
}

#[PARAMETER END]
#[SECTION STARTS]
section {
name = "section 1"
#[ROW STARTS]
row {
#[CHART STARTS]
chart {
name = "chart 1"
description = "chart number 1"
units = "something per unit"
source {
name = "source name"
query = "ts(~http.api.extlink.simple.GET.200.count)"
}
chart_setting {
type = "line"
}
summarization = "MEAN"
}
chart {
name = "chart 2"
description = "chart number 2"
units = "something per unit"
source {
name = "source name"
query = "ts(~http.api.extlink.simple.GET.200.count)"
}
chart_setting {
type = "line"
}
summarization = "MEAN"
}

#[CHART ENDS]
}
#[ROW ENDS]
}
#[SECTION ENDS]
tags = [
"terraform",
"test"
]
}

Run terraform to apply the changes.

terraform apply

Which will modify the Dashboard named “Terraform Dashboard Test”. It will introduce a new “Parameter” named “param2” with value as “test2” and creates another “Chart” under the existing “Row”.

Play around with the above “main.tf” to add more “Sections” and “Rows”. We will see how to add “Alert Targets” in the next article.

In Part III, we will discuss on how to add an “Alert Target” and how to attach it with “Alerts”.

References:

  1. https://github.com/spaceapegames/terraform-provider-wavefront

--

--

Responses (1)