Skip to content

Commit

Permalink
Add a module for loading Prometheus rules.
Browse files Browse the repository at this point in the history
Save Prometheus URL and user id to SSM
  • Loading branch information
avnes committed Oct 16, 2024
1 parent 1ed95b2 commit 1280f2d
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 0 deletions.
11 changes: 11 additions & 0 deletions grafana_prometheus_rules/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
resource "terraform_data" "this" {
count = length(var.prometheus_rule_files)

triggers_replace = {
always_run = filemd5(var.prometheus_rule_files[count.index]) # Only run when the file changes
}

provisioner "local-exec" {
command = "mimirtool rules load --address=${var.prometheus_url} --id=${var.prometheus_user_id} --key=${var.rules_management_access_token} ${var.prometheus_rule_files[count.index]}"
}
}
20 changes: 20 additions & 0 deletions grafana_prometheus_rules/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
variable "prometheus_rule_files" {
description = "Path to the yaml files with Prometheus rules"
type = list(string)
}

variable "prometheus_url" {
description = "Prometheus URL"
type = string
}

variable "prometheus_user_id" {
description = "Prometheus User ID"
type = string
}

variable "rules_management_access_token" {
description = "Token"
type = string
sensitive = true
}
3 changes: 3 additions & 0 deletions grafana_prometheus_rules/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
terraform {
required_version = ">= 1.3.0, < 1.6.0"
}
3 changes: 3 additions & 0 deletions grafana_prometheus_rules/versions.tofu
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
terraform {
required_version = ">= 1.8.0"
}
18 changes: 18 additions & 0 deletions stack.tf
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,24 @@ resource "aws_ssm_parameter" "rules_management" {
value = grafana_cloud_access_policy_token.rules_management[0].token
}

# trunk-ignore(checkov/CKV2_AWS_34)
resource "aws_ssm_parameter" "prometheus_url" {
provider = aws.route53

name = "/grafana-cloud/${var.slug}/prometheus-url"
type = "String"
value = grafana_cloud_stack.this.prometheus_url
}

# trunk-ignore(checkov/CKV_AWS_337)
resource "aws_ssm_parameter" "prometheus_user_id" {
provider = aws.route53

name = "/grafana-cloud/${var.slug}/prometheus-user-id"
type = "SecureString"
value = grafana_cloud_stack.this.prometheus_user_id
}

resource "aws_ssm_parameter" "otlp_endpoint" {
count = var.create_write_only_token ? 1 : 0
provider = aws.route53
Expand Down

0 comments on commit 1280f2d

Please sign in to comment.