feat(observability): Add missing support for OpsGenie priority level (#931)

relates to STACKITCDN-879

Co-authored-by: Ruben Hoenle <Ruben.Hoenle@stackit.cloud>
This commit is contained in:
Christian Hamm 2025-08-25 17:25:19 +02:00 committed by GitHub
parent 4b670ee73f
commit 971cd27e4b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 47 additions and 24 deletions

View file

@ -110,6 +110,7 @@ Read-Only:
- `api_key` (String) The API key for OpsGenie.
- `api_url` (String) The host to send OpsGenie API requests to. Must be a valid URL
- `priority` (String) Priority of the alert. Possible values are: `P1`, `P2`, `P3`, `P4`, `P5`.
- `tags` (String) Comma separated list of tags attached to the notifications.

View file

@ -115,6 +115,7 @@ Optional:
- `api_key` (String) The API key for OpsGenie.
- `api_url` (String) The host to send OpsGenie API requests to. Must be a valid URL
- `priority` (String) Priority of the alert. Possible values are: `P1`, `P2`, `P3`, `P4`, `P5`.
- `tags` (String) Comma separated list of tags attached to the notifications.

View file

@ -247,6 +247,10 @@ func (d *instanceDataSource) Schema(_ context.Context, _ datasource.SchemaReques
Description: "Comma separated list of tags attached to the notifications.",
Computed: true,
},
"priority": schema.StringAttribute{
Description: "Priority of the alert. " + utils.FormatPossibleValues([]string{"P1", "P2", "P3", "P4", "P5"}...),
Computed: true,
},
},
},
},

View file

@ -187,15 +187,17 @@ var emailConfigsTypes = map[string]attr.Type{
// Struct corresponding to Model.AlertConfig.receivers.opsGenieConfigs
type opsgenieConfigsModel struct {
ApiKey types.String `tfsdk:"api_key"`
ApiUrl types.String `tfsdk:"api_url"`
Tags types.String `tfsdk:"tags"`
ApiKey types.String `tfsdk:"api_key"`
ApiUrl types.String `tfsdk:"api_url"`
Tags types.String `tfsdk:"tags"`
Priority types.String `tfsdk:"priority"`
}
var opsgenieConfigsTypes = map[string]attr.Type{
"api_key": types.StringType,
"api_url": types.StringType,
"tags": types.StringType,
"api_key": types.StringType,
"api_url": types.StringType,
"tags": types.StringType,
"priority": types.StringType,
}
// Struct corresponding to Model.AlertConfig.receivers.webHooksConfigs
@ -629,6 +631,10 @@ func (r *instanceResource) Schema(_ context.Context, _ resource.SchemaRequest, r
Description: "Comma separated list of tags attached to the notifications.",
Optional: true,
},
"priority": schema.StringAttribute{
Description: "Priority of the alert. " + utils.FormatPossibleValues("P1", "P2", "P3", "P4", "P5"),
Optional: true,
},
},
},
},
@ -1665,9 +1671,10 @@ func mapReceiversToAttributes(ctx context.Context, respReceivers *[]observabilit
if receiver.OpsgenieConfigs != nil {
for _, opsgenieConfig := range *receiver.OpsgenieConfigs {
opsGenieConfigMap := map[string]attr.Value{
"api_key": types.StringPointerValue(opsgenieConfig.ApiKey),
"api_url": types.StringPointerValue(opsgenieConfig.ApiUrl),
"tags": types.StringPointerValue(opsgenieConfig.Tags),
"api_key": types.StringPointerValue(opsgenieConfig.ApiKey),
"api_url": types.StringPointerValue(opsgenieConfig.ApiUrl),
"tags": types.StringPointerValue(opsgenieConfig.Tags),
"priority": types.StringPointerValue(opsgenieConfig.Priority),
}
opsGenieConfigModel, diags := types.ObjectValue(opsgenieConfigsTypes, opsGenieConfigMap)
if diags.HasError() {
@ -2014,9 +2021,10 @@ func toReceiverPayload(ctx context.Context, model *alertConfigModel) (*[]observa
for i := range opsgenieConfigs {
opsgenieConfig := opsgenieConfigs[i]
payloadOpsGenieConfigs = append(payloadOpsGenieConfigs, observability.CreateAlertConfigReceiverPayloadOpsgenieConfigsInner{
ApiKey: conversion.StringValueToPointer(opsgenieConfig.ApiKey),
ApiUrl: conversion.StringValueToPointer(opsgenieConfig.ApiUrl),
Tags: conversion.StringValueToPointer(opsgenieConfig.Tags),
ApiKey: conversion.StringValueToPointer(opsgenieConfig.ApiKey),
ApiUrl: conversion.StringValueToPointer(opsgenieConfig.ApiUrl),
Tags: conversion.StringValueToPointer(opsgenieConfig.Tags),
Priority: conversion.StringValueToPointer(opsgenieConfig.Priority),
})
}
receiverPayload.OpsgenieConfigs = &payloadOpsGenieConfigs

View file

@ -33,9 +33,10 @@ func fixtureEmailConfigsModel() basetypes.ListValue {
func fixtureOpsGenieConfigsModel() basetypes.ListValue {
return types.ListValueMust(types.ObjectType{AttrTypes: opsgenieConfigsTypes}, []attr.Value{
types.ObjectValueMust(opsgenieConfigsTypes, map[string]attr.Value{
"api_key": types.StringValue("key"),
"tags": types.StringValue("tag"),
"api_url": types.StringValue("ops.example.com"),
"api_key": types.StringValue("key"),
"tags": types.StringValue("tag"),
"api_url": types.StringValue("ops.example.com"),
"priority": types.StringValue("P3"),
}),
})
}
@ -140,9 +141,10 @@ func fixtureEmailConfigsPayload() observability.CreateAlertConfigReceiverPayload
func fixtureOpsGenieConfigsPayload() observability.CreateAlertConfigReceiverPayloadOpsgenieConfigsInner {
return observability.CreateAlertConfigReceiverPayloadOpsgenieConfigsInner{
ApiKey: utils.Ptr("key"),
Tags: utils.Ptr("tag"),
ApiUrl: utils.Ptr("ops.example.com"),
ApiKey: utils.Ptr("key"),
Tags: utils.Ptr("tag"),
ApiUrl: utils.Ptr("ops.example.com"),
Priority: utils.Ptr("P3"),
}
}
@ -220,9 +222,10 @@ func fixtureEmailConfigsResponse() observability.EmailConfig {
func fixtureOpsGenieConfigsResponse() observability.OpsgenieConfig {
return observability.OpsgenieConfig{
ApiKey: utils.Ptr("key"),
Tags: utils.Ptr("tag"),
ApiUrl: utils.Ptr("ops.example.com"),
ApiKey: utils.Ptr("key"),
Tags: utils.Ptr("tag"),
ApiUrl: utils.Ptr("ops.example.com"),
Priority: utils.Ptr("P3"),
}
}

View file

@ -84,6 +84,7 @@ var testConfigVarsMax = config.Variables{
"opsgenie_api_key": config.StringVariable("example-api-key"),
"opsgenie_api_tags": config.StringVariable("observability-alert"),
"opsgenie_api_url": config.StringVariable("https://api.eu.opsgenie.com"),
"opsgenie_priority": config.StringVariable("P3"),
"webhook_configs_url": config.StringVariable("https://example.com"),
"ms_teams": config.StringVariable("true"),
"group_by": config.StringVariable("alertname"),
@ -505,6 +506,7 @@ func TestAccResourceMax(t *testing.T) {
resource.TestCheckResourceAttr("stackit_observability_instance.instance", "alert_config.receivers.0.opsgenie_configs.0.api_key", testutil.ConvertConfigVariable(testConfigVarsMax["opsgenie_api_key"])),
resource.TestCheckResourceAttr("stackit_observability_instance.instance", "alert_config.receivers.0.opsgenie_configs.0.tags", testutil.ConvertConfigVariable(testConfigVarsMax["opsgenie_api_tags"])),
resource.TestCheckResourceAttr("stackit_observability_instance.instance", "alert_config.receivers.0.opsgenie_configs.0.api_url", testutil.ConvertConfigVariable(testConfigVarsMax["opsgenie_api_url"])),
resource.TestCheckResourceAttr("stackit_observability_instance.instance", "alert_config.receivers.0.opsgenie_configs.0.priority", testutil.ConvertConfigVariable(testConfigVarsMax["opsgenie_priority"])),
resource.TestCheckResourceAttr("stackit_observability_instance.instance", "alert_config.receivers.0.webhooks_configs.0.url", testutil.ConvertConfigVariable(testConfigVarsMax["webhook_configs_url"])),
resource.TestCheckResourceAttr("stackit_observability_instance.instance", "alert_config.receivers.0.webhooks_configs.0.ms_teams", testutil.ConvertConfigVariable(testConfigVarsMax["ms_teams"])),
@ -666,6 +668,7 @@ func TestAccResourceMax(t *testing.T) {
resource.TestCheckResourceAttr("data.stackit_observability_instance.instance", "alert_config.receivers.0.opsgenie_configs.0.api_key", testutil.ConvertConfigVariable(testConfigVarsMax["opsgenie_api_key"])),
resource.TestCheckResourceAttr("data.stackit_observability_instance.instance", "alert_config.receivers.0.opsgenie_configs.0.tags", testutil.ConvertConfigVariable(testConfigVarsMax["opsgenie_api_tags"])),
resource.TestCheckResourceAttr("data.stackit_observability_instance.instance", "alert_config.receivers.0.opsgenie_configs.0.api_url", testutil.ConvertConfigVariable(testConfigVarsMax["opsgenie_api_url"])),
resource.TestCheckResourceAttr("data.stackit_observability_instance.instance", "alert_config.receivers.0.opsgenie_configs.0.priority", testutil.ConvertConfigVariable(testConfigVarsMax["opsgenie_priority"])),
resource.TestCheckResourceAttr("data.stackit_observability_instance.instance", "alert_config.receivers.0.webhooks_configs.0.url", testutil.ConvertConfigVariable(testConfigVarsMax["webhook_configs_url"])),
resource.TestCheckResourceAttr("data.stackit_observability_instance.instance", "alert_config.receivers.0.webhooks_configs.0.ms_teams", testutil.ConvertConfigVariable(testConfigVarsMax["ms_teams"])),
@ -888,6 +891,7 @@ func TestAccResourceMax(t *testing.T) {
resource.TestCheckResourceAttr("stackit_observability_instance.instance", "alert_config.receivers.0.opsgenie_configs.0.api_key", testutil.ConvertConfigVariable(testConfigVarsMax["opsgenie_api_key"])),
resource.TestCheckResourceAttr("stackit_observability_instance.instance", "alert_config.receivers.0.opsgenie_configs.0.tags", testutil.ConvertConfigVariable(testConfigVarsMax["opsgenie_api_tags"])),
resource.TestCheckResourceAttr("stackit_observability_instance.instance", "alert_config.receivers.0.opsgenie_configs.0.api_url", testutil.ConvertConfigVariable(testConfigVarsMax["opsgenie_api_url"])),
resource.TestCheckResourceAttr("stackit_observability_instance.instance", "alert_config.receivers.0.opsgenie_configs.0.priority", testutil.ConvertConfigVariable(testConfigVarsMax["opsgenie_priority"])),
resource.TestCheckResourceAttr("stackit_observability_instance.instance", "alert_config.receivers.0.webhooks_configs.0.url", testutil.ConvertConfigVariable(testConfigVarsMax["webhook_configs_url"])),
resource.TestCheckResourceAttr("stackit_observability_instance.instance", "alert_config.receivers.0.webhooks_configs.0.ms_teams", testutil.ConvertConfigVariable(testConfigVarsMax["ms_teams"])),

View file

@ -26,6 +26,7 @@ variable "email_to" {}
variable "opsgenie_api_key" {}
variable "opsgenie_api_tags" {}
variable "opsgenie_api_url" {}
variable "opsgenie_priority" {}
variable "webhook_configs_url" {}
variable "ms_teams" {}
variable "group_by" {}
@ -114,9 +115,10 @@ resource "stackit_observability_instance" "instance" {
]
opsgenie_configs = [
{
api_key = var.opsgenie_api_key
tags = var.opsgenie_api_tags
api_url = var.opsgenie_api_url
api_key = var.opsgenie_api_key
tags = var.opsgenie_api_tags
api_url = var.opsgenie_api_url
priority = var.opsgenie_priority
}
]
webhooks_configs = [