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

@ -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"),
}
}