Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/fgouteroux/loki2tf

Loki YAML Prometheus Rules to Terraform HCL converter
https://github.com/fgouteroux/loki2tf

Last synced: about 7 hours ago
JSON representation

Loki YAML Prometheus Rules to Terraform HCL converter

Awesome Lists containing this project

README

        

# loki2tf - Loki YAML Prometheus-compatible Rules to Terraform HCL converter

A tool for converting Loki Prometheus-compatible Rules (in YAML format) into HashiCorp's Terraform configuration language.

The converted `.tf` files are suitable for use with the [Terraform Loki Provider](https://registry.terraform.io/providers/fgouteroux/loki/latest/docs)

## Installation

**Pre-built Binaries**

Download Binary from GitHub [releases](https://github.com/fgouteroux/loki2tf/releases/latest) page.

## YAML to HCL

**Convert a single YAML file and write generated Terraform config to Stdout**

```
$ loki2tf -f test-fixtures/rules.yaml

resource "loki_rule_group_alerting" "should_fire" {
name = "should_fire"

rule {
alert = "HighPercentageError"

expr = < 0.05
EOT

for = "10m"

labels = {
severity = "page"
}

annotations = {
summary = "High request latency"
}
}
}

resource "loki_rule_group_alerting" "credentials_leak" {
name = "credentials_leak"

rule {
alert = "http-credentials-leaked"
expr = "sum by (cluster, job, pod) (count_over_time({namespace=\"prod\"} |~ \"http(s?)://(\\w+):(\\w+)@\" [5m]) > 0)"
for = "10m"

labels = {
severity = "critical"
}

annotations = {
message = "{{ $labels.job }} is leaking http basic auth credentials."
}
}
}

resource "loki_rule_group_recording" "NginxRules" {
name = "NginxRules"

rule {
record = "nginx:requests:rate1m"

expr = < **NOTE** Requires a working Golang build environment.

This project uses Golang modules for dependency management, so it can be cloned outside of the `$GOPATH`.

**Clone the repository**

```
$ git clone https://github.com/fgouteroux/loki2tf.git
```

**Build**

```
$ cd loki2tf
$ make build
```