diff --git a/grafana_prometheus_rules/main.tf b/grafana_prometheus_rules/main.tf new file mode 100644 index 0000000..4f241d9 --- /dev/null +++ b/grafana_prometheus_rules/main.tf @@ -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]}" + } +} diff --git a/grafana_prometheus_rules/variables.tf b/grafana_prometheus_rules/variables.tf new file mode 100644 index 0000000..97e6131 --- /dev/null +++ b/grafana_prometheus_rules/variables.tf @@ -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 +} diff --git a/grafana_prometheus_rules/versions.tf b/grafana_prometheus_rules/versions.tf new file mode 100644 index 0000000..525156c --- /dev/null +++ b/grafana_prometheus_rules/versions.tf @@ -0,0 +1,3 @@ +terraform { + required_version = ">= 1.3.0, < 1.6.0" +} diff --git a/grafana_prometheus_rules/versions.tofu b/grafana_prometheus_rules/versions.tofu new file mode 100644 index 0000000..1e3f40b --- /dev/null +++ b/grafana_prometheus_rules/versions.tofu @@ -0,0 +1,3 @@ +terraform { + required_version = ">= 1.8.0" +} diff --git a/stack.tf b/stack.tf index 74594a6..a366426 100644 --- a/stack.tf +++ b/stack.tf @@ -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