Skip to content

Add support for Recording Rules (record field) in stackit_observability_alertgroup #1115

@jojomo96

Description

@jojomo96

Problem description

I am unable to create Prometheus Recording Rules using the stackit_observability_alertgroup resource because the resource schema enforces that every rule must be an Alerting Rule.

When I attempt to create a Recording Rule (by omitting alert and trying to use record), Terraform fails because the provider has marked the alert attribute as required.

Since a Prometheus Rule cannot be both an Alert and a Record simultaneously, it is currently impossible to use this resource for Recording Rules, even though the backend API supports them.

Actual Error Log

Error: Incorrect attribute value type

   on main.tf line 101, in resource "stackit_observability_alertgroup" "test_recording_rule":
  101:    rules = [
  102:      {
  103:        record = "test_availability"
  104:        expr   = "1"
  105:      }
  106:    ]

Inappropriate value for attribute "rules": element 0: attributes "alert" and "expression" are required.

Proposed solution

Please update the stackit_observability_alertgroup resource schema to:

  1. Make alert optional (currently it is required).
  2. Add an optional record field (string).
  3. Add validation to ensure that either alert or record is set (but not both).

This would allow users to define both rule types in the same resource, matching standard Prometheus/Thanos functionality.

resource "stackit_observability_alertgroup" "dns_availability" {
  project_id   = var.project_id
  instance_id  = var.instance_id
  name         = "DNSAvailability"
  
  # Proposed: This should work for Recording Rules
  rules = [
    {
      record = "availability"  # <--- Currently triggers "Unsupported argument"
      # alert = ...            # <--- Currently "Required", making records impossible
      
      expr   = "1 - min(dns_query_result_code) by (product)"
      labels = {
        product = "dns"
      }
    }
  ]
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions