Wavefront as Code using Terraform Integration — Part I

Sanooj Mananghat
4 min readMar 22, 2019

Understanding the state of your infrastructure and systems is essential for ensuring the reliability and stability of services. Best way to gain this insight is with a robust monitoring system that gathers metrics, visualizes data, and alerts when things appear to be broken.

Wavefront is one of the popular analytics and monitoring platform.

Configuring and modifying dashboards and alerts by hand are error-prone. Versioning dashboards and alerts using “Infrastructure as code” are extremely useful in a fast-paced environment and when things go south. Also, managing a service programmatically give us more control over the configuration of service.

The “Wavefront Terraform Provider” is a custom third-party terraform provider plugin from SpaceApeGames that enables users to manage resources on Wavefront as code. This integration currently supports Alerts, Alert targets, and Dashboards.

How to setup?

Terraform installation is a single step process. Download terraform binary and unzip it. Make sure that the terraform binary is available on the PATH.

For more information on installation, refer Hashicorp documentation here.

Let's create a directory for terraform scripts.

mkdir wavefront_alerts

Download the latest “terraform-provider-wavefront” plugin from the git repo.
Plugins for MacOS(Darwin) and Linux Systems can be downloaded directly from here.

Terraform expects the third-party plugins to be available in terraform.d/plugins/<os_arch>/ under the parent directory.

mkdir -p wavefront_alerts/terraform.d/plugins/<os_arch>

where <os_arch> can be any of the following depending on the OS:

darwin_amd64
freebsd_386
freebsd_amd64
freebsd_arm
linux_386
linux_amd64
linux_arm
openbsd_386
openbsd_amd64
solaris_amd64
windows_386
windows_amd64

For MacOs the directory should be darwin_amd64

mkdir -p wavefront_alerts/terraform.d/plugins/darwin_amd64

Copy the downloaded plugin to the above-created directory.

mv ~/Downloads/terraform-provider-wavefront_v1.1.0_darwin_amd64 wavefront_alerts/terraform.d/plugins/darwin_amd64/

Once copied, rename the file to follow the naming scheme for provider plugins. ie. terraform-provider-<NAME>_vX.Y.Z

mv terraform-provider-wavefront_v1.1.0_darwin_amd64 terraform-provider-wavefront_v1.1.0

Ensure that the plugin has proper permission.

chmod 755 terraform-provider-wavefront_v1.1.0

With 0.10.0 release, Terraform third-party providers are no longer distributed as part of the main Terraform distribution. Instead, they are installed automatically as part of running terraform init.

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

Create a terraform file “main.tf” and define the provider and alert definition.

provider "wavefront" {
address = "try.wavefront.com"
token = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}
resource "wavefront_alert" "test_alert" {
name = "Terraform Test Alert"
target = "stest@example.com"
condition = "100-ts(\"cpu.usage_idle\", environment=flamingo-int and cpu=cpu-total and service=game-service) > 80"
display_expression = "100-ts(\"cpu.usage_idle\", environment=flamingo-int and cpu=cpu-total and service=game-service)"
minutes = 5
resolve_after_minutes = 5
severity = "WARN"
tags = [
"terraform",
"flamingo"
]
}

Token and Address can be found under the API Access section in your user profile page. URI: /userprofile/apiaccess

Ex: https://longboard.wavefront.com/userprofile/apiaccess

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

It is mandatory to run “terraform init” before any other operations that use provider plugins, to ensure that the required plugins are installed and properly initialized.

Initialize a new Terraform configuration

terraform init
terraform init output

Generate and show the execution plan

terraform plan
terraform plan output

Builds or changes infrastructure.

terraform apply
terraform apply output

Alert will now be created with the name “Terraform Test Alert”.

Alert in Wavefront UI

In the next article, we will see how to create a Wavefront Dashboard as code using Terraform.

References:
1. https://docs.wavefront.com/wavefront-terraform-provider.html
2. https://github.com/spaceapegames/terraform-provider-wavefront

--

--