SLOs as Code via the Nobl9 Terraform Provider

SLOs as Code via the Nobl9 Terraform Provider

More by Tomek Labuk:

Terraform has rapidly grown to be the tool of choice for SREs and Engineers to manage their cloud infrastructure. To ensure their infrastructure and SLOs are updated and maintained, engineers are looking for a way to store their Terraform configs and SLOs in a single place and update their SLOs and infrastructure simultaneously.

This requires a repeatable process and the ability to store and manage their SLOs in a single configuration file. Leveraging Terraform, users can easily define and configure their cloud infrastructure and SLOs using either a declarative configuration language (HCL) or a JSON config file.

With the help of several early adopters, Nobl9 built and released a Terraform provider for SLOs. We released our initial Beta version of the Nobl9 Terraform provider earlier this year, and we continued updating it to enhance the features it supports, fix bugs, and add feature requests from our customers.

The Nobl9 Terraform Provider delivers tools that work with the Nobl9 API to create and manage the following Nobl9 resources:

- SLOs

- Services

- Projects

- Alert Policies

- Alert Methods

- Data Sources

- Role Bindings

On top of these, the latest Nobl9 Terraform provider added support for Labels that allow users to define attributes of resources such as Projects, Services and SLOs, and use them to filter and easily group them.

Getting Started with the Nobl9 Terraform Provider

To start using Nobl9 Terraform Provider, you must configure the provider with the proper credentials. Here’s an example of Terraform Nobl9 provider configuration:

terraform {
  required_providers {
    nobl9 = {
      source  = "nobl9/nobl9"
      version = "0.6.0"
    }
  }
}

provider "nobl9" {
  organization  = "<your org name>"
  project       = "default"
  client_id     = "<client_id>"
  client_secret = "<client_secret>"
}

Using Terraform with Nobl9

Below, you can see some examples of how you can create and manage Nobl9 resources with Terraform.

For instance, you can use Terraform to add your Nobl9 Agents to connect to data sources and start collecting your metrics data. Here’s an example of the Terraform configuration for the Nobl9 Prometheus agent:

resource "nobl9_agent" "web-prometheus" {
  project = "web-project"
  name = "web-prometheus"
  source_of = ["Metrics"]
  agent_type = "prometheus"

  prometheus_config {
    url = ""http://prometheus.example.com""
  }
}

You can also manage and create your SLOs. Here’s an example of a Nobl9 SLO created via Terraform:

resource "nobl9_slo" "web-slo" {
  name             = "web-slo"
  service          = "web-service"
  budgeting_method = "Occurrences"
  project          = "web-project"

  label {
    key = "team"
    values = ["engineering"]
  }

  depends_on = [nobl9_agent.web-prometheus]

  time_window {
    unit       = "Day"
    count      = 14
    is_rolling = true
  }

  objective {
    target       = 0.999
    value        = 5
    display_name = "Good"
    op           = "lte"

    raw_metric {
      query {
        prometheus {
          promql = "server_requestMsec{host=\"*\",instance=\"143.146.168.125:9913\",job=\"nginx\"}"
        }
      }
    }
  }

  indicator {
    name    = "web-prometheus"
    kind    = "Agent"
    project = "web-project"
  }
}

The Nobl9 Terraform provider allows you to create and define Alert Policies and append defined Alert Methods to your SLOs:

resource "nobl9_alert_policy" "default" {
  name       = “default"
  project    = "default"
  severity   = "Medium"
  condition {
    measurement = "burnedBudget"
value   = 0.9
  }
  condition {
    measurement = "averageBurnRate"
value   = 3
lasts_for   = "1m"
  }
  condition {
measurement  = "timeToBurnBudget"
value_string = "1h"
lasts_for   = "300s"
  }
}


resource "nobl9_alert_method_discord" "web-alert-metehod" {
  name         = "web-alert"
  display_name = "web Alert"
  project      = "we-project"
  description = "discord"
  url         = "https://discord.webhook.url"
}

For more details on how to use the Nobl9 Terraform provider, check the Nobl9 Terraform documentation. And, as we keep developing Nobl9, stay tuned for more upcoming features!

Useful links:

Nobl9 Terraform Provider Documentation

Nobl9 Terraform Provider Repository

Nobl9 Documentation

SLOs in Minutes, Not Months

Get Started with Nobl9 Reliability Center Free Edition

Start Now

Do you want to add something? Leave a comment