From 6090803bf08f13e98cfa3e0519a0427b8c88bee7 Mon Sep 17 00:00:00 2001 From: Ruben Hoenle Date: Fri, 18 Jul 2025 11:39:18 +0200 Subject: [PATCH] feat(observability): add send_resolved field relates to STACKITTPR-283 --- docs/data-sources/observability_instance.md | 3 + docs/resources/observability_instance.md | 3 + .../observability/instance/datasource.go | 12 ++++ .../observability/instance/resource.go | 65 +++++++++++++------ .../observability/instance/resource_test.go | 39 ++++++----- .../observability/observability_acc_test.go | 3 + .../observability/testdata/resource-max.tf | 6 ++ 7 files changed, 96 insertions(+), 35 deletions(-) diff --git a/docs/data-sources/observability_instance.md b/docs/data-sources/observability_instance.md index 0f70fe8c2..b8a736b47 100644 --- a/docs/data-sources/observability_instance.md +++ b/docs/data-sources/observability_instance.md @@ -99,6 +99,7 @@ Read-Only: - `auth_password` (String) SMTP authentication password. - `auth_username` (String) SMTP authentication username. - `from` (String) The sender email address. Must be a valid email address +- `send_resolved` (Boolean) Whether to notify about resolved alerts. - `smart_host` (String) The SMTP host through which emails are sent. - `to` (String) The email address to send notifications to. Must be a valid email address @@ -110,6 +111,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 +- `send_resolved` (Boolean) Whether to notify about resolved alerts. - `tags` (String) Comma separated list of tags attached to the notifications. @@ -119,6 +121,7 @@ Read-Only: Read-Only: - `ms_teams` (Boolean) Microsoft Teams webhooks require special handling, set this to true if the webhook is for Microsoft Teams. +- `send_resolved` (Boolean) Whether to notify about resolved alerts. - `url` (String) The endpoint to send HTTP POST requests to. Must be a valid URL diff --git a/docs/resources/observability_instance.md b/docs/resources/observability_instance.md index 3c8cebbd5..d3f69e4bb 100644 --- a/docs/resources/observability_instance.md +++ b/docs/resources/observability_instance.md @@ -98,6 +98,7 @@ Optional: - `auth_password` (String) SMTP authentication password. - `auth_username` (String) SMTP authentication username. - `from` (String) The sender email address. Must be a valid email address +- `send_resolved` (Boolean) Whether to notify about resolved alerts. - `smart_host` (String) The SMTP host through which emails are sent. - `to` (String) The email address to send notifications to. Must be a valid email address @@ -109,6 +110,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 +- `send_resolved` (Boolean) Whether to notify about resolved alerts. - `tags` (String) Comma separated list of tags attached to the notifications. @@ -118,6 +120,7 @@ Optional: Optional: - `ms_teams` (Boolean) Microsoft Teams webhooks require special handling, set this to true if the webhook is for Microsoft Teams. +- `send_resolved` (Boolean) Whether to notify about resolved alerts. - `url` (String) The endpoint to send HTTP POST requests to. Must be a valid URL diff --git a/stackit/internal/services/observability/instance/datasource.go b/stackit/internal/services/observability/instance/datasource.go index d55a4d292..dae49629d 100644 --- a/stackit/internal/services/observability/instance/datasource.go +++ b/stackit/internal/services/observability/instance/datasource.go @@ -219,6 +219,10 @@ func (d *instanceDataSource) Schema(_ context.Context, _ datasource.SchemaReques Description: "The sender email address. Must be a valid email address", Computed: true, }, + "send_resolved": schema.BoolAttribute{ + Description: "Whether to notify about resolved alerts.", + Computed: true, + }, "smart_host": schema.StringAttribute{ Description: "The SMTP host through which emails are sent.", Computed: true, @@ -247,6 +251,10 @@ func (d *instanceDataSource) Schema(_ context.Context, _ datasource.SchemaReques Description: "Comma separated list of tags attached to the notifications.", Computed: true, }, + "send_resolved": schema.BoolAttribute{ + Description: "Whether to notify about resolved alerts.", + Computed: true, + }, }, }, }, @@ -263,6 +271,10 @@ func (d *instanceDataSource) Schema(_ context.Context, _ datasource.SchemaReques Description: "Microsoft Teams webhooks require special handling, set this to true if the webhook is for Microsoft Teams.", Computed: true, }, + "send_resolved": schema.BoolAttribute{ + Description: "Whether to notify about resolved alerts.", + Computed: true, + }, }, }, }, diff --git a/stackit/internal/services/observability/instance/resource.go b/stackit/internal/services/observability/instance/resource.go index 36b7e4d85..e8dcf754e 100644 --- a/stackit/internal/services/observability/instance/resource.go +++ b/stackit/internal/services/observability/instance/resource.go @@ -172,6 +172,7 @@ type emailConfigsModel struct { AuthPassword types.String `tfsdk:"auth_password"` AuthUsername types.String `tfsdk:"auth_username"` From types.String `tfsdk:"from"` + SendResolved types.Bool `tfsdk:"send_resolved"` Smarthost types.String `tfsdk:"smart_host"` To types.String `tfsdk:"to"` } @@ -181,32 +182,37 @@ var emailConfigsTypes = map[string]attr.Type{ "auth_password": types.StringType, "auth_username": types.StringType, "from": types.StringType, + "send_resolved": types.BoolType, "smart_host": types.StringType, "to": types.StringType, } // 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"` + SendResolved types.Bool `tfsdk:"send_resolved"` } 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, + "send_resolved": types.BoolType, } // Struct corresponding to Model.AlertConfig.receivers.webHooksConfigs type webHooksConfigsModel struct { - Url types.String `tfsdk:"url"` - MsTeams types.Bool `tfsdk:"ms_teams"` + Url types.String `tfsdk:"url"` + MsTeams types.Bool `tfsdk:"ms_teams"` + SendResolved types.Bool `tfsdk:"send_resolved"` } var webHooksConfigsTypes = map[string]attr.Type{ - "url": types.StringType, - "ms_teams": types.BoolType, + "url": types.StringType, + "ms_teams": types.BoolType, + "send_resolved": types.BoolType, } var routeDescriptions = map[string]string{ @@ -598,6 +604,10 @@ func (r *instanceResource) Schema(_ context.Context, _ resource.SchemaRequest, r Description: "The sender email address. Must be a valid email address", Optional: true, }, + "send_resolved": schema.BoolAttribute{ + Description: "Whether to notify about resolved alerts.", + Optional: true, + }, "smart_host": schema.StringAttribute{ Description: "The SMTP host through which emails are sent.", Optional: true, @@ -629,6 +639,10 @@ func (r *instanceResource) Schema(_ context.Context, _ resource.SchemaRequest, r Description: "Comma separated list of tags attached to the notifications.", Optional: true, }, + "send_resolved": schema.BoolAttribute{ + Description: "Whether to notify about resolved alerts.", + Optional: true, + }, }, }, }, @@ -648,6 +662,10 @@ func (r *instanceResource) Schema(_ context.Context, _ resource.SchemaRequest, r Description: "Microsoft Teams webhooks require special handling, set this to true if the webhook is for Microsoft Teams.", Optional: true, }, + "send_resolved": schema.BoolAttribute{ + Description: "Whether to notify about resolved alerts.", + Optional: true, + }, }, }, }, @@ -1503,6 +1521,7 @@ func getMockAlertConfig(ctx context.Context) (alertConfigModel, error) { mockEmailConfig, diags := types.ObjectValue(emailConfigsTypes, map[string]attr.Value{ "to": types.StringValue("123@gmail.com"), "smart_host": types.StringValue("smtp.gmail.com:587"), + "send_resolved": types.BoolValue(false), "from": types.StringValue("xxxx@gmail.com"), "auth_username": types.StringValue("xxxx@gmail.com"), "auth_password": types.StringValue("xxxxxxxxx"), @@ -1650,6 +1669,7 @@ func mapReceiversToAttributes(ctx context.Context, respReceivers *[]observabilit "auth_password": types.StringPointerValue(emailConfig.AuthPassword), "auth_username": types.StringPointerValue(emailConfig.AuthUsername), "from": types.StringPointerValue(emailConfig.From), + "send_resolved": types.BoolPointerValue(emailConfig.SendResolved), "smart_host": types.StringPointerValue(emailConfig.Smarthost), "to": types.StringPointerValue(emailConfig.To), } @@ -1665,9 +1685,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), + "send_resolved": types.BoolPointerValue(opsgenieConfig.SendResolved), } opsGenieConfigModel, diags := types.ObjectValue(opsgenieConfigsTypes, opsGenieConfigMap) if diags.HasError() { @@ -1681,8 +1702,9 @@ func mapReceiversToAttributes(ctx context.Context, respReceivers *[]observabilit if receiver.WebHookConfigs != nil { for _, webhookConfig := range *receiver.WebHookConfigs { webHookConfigsMap := map[string]attr.Value{ - "url": types.StringPointerValue(webhookConfig.Url), - "ms_teams": types.BoolPointerValue(webhookConfig.MsTeams), + "url": types.StringPointerValue(webhookConfig.Url), + "ms_teams": types.BoolPointerValue(webhookConfig.MsTeams), + "send_resolved": types.BoolPointerValue(webhookConfig.SendResolved), } webHookConfigsModel, diags := types.ObjectValue(webHooksConfigsTypes, webHookConfigsMap) if diags.HasError() { @@ -1997,6 +2019,7 @@ func toReceiverPayload(ctx context.Context, model *alertConfigModel) (*[]observa AuthPassword: conversion.StringValueToPointer(emailConfig.AuthPassword), AuthUsername: conversion.StringValueToPointer(emailConfig.AuthUsername), From: conversion.StringValueToPointer(emailConfig.From), + SendResolved: conversion.BoolValueToPointer(emailConfig.SendResolved), Smarthost: conversion.StringValueToPointer(emailConfig.Smarthost), To: conversion.StringValueToPointer(emailConfig.To), }) @@ -2014,9 +2037,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), + SendResolved: conversion.BoolValueToPointer(opsgenieConfig.SendResolved), }) } receiverPayload.OpsgenieConfigs = &payloadOpsGenieConfigs @@ -2032,8 +2056,9 @@ func toReceiverPayload(ctx context.Context, model *alertConfigModel) (*[]observa for i := range receiverWebHooksConfigs { webHooksConfig := receiverWebHooksConfigs[i] payloadWebHooksConfigs = append(payloadWebHooksConfigs, observability.CreateAlertConfigReceiverPayloadWebHookConfigsInner{ - Url: conversion.StringValueToPointer(webHooksConfig.Url), - MsTeams: conversion.BoolValueToPointer(webHooksConfig.MsTeams), + Url: conversion.StringValueToPointer(webHooksConfig.Url), + MsTeams: conversion.BoolValueToPointer(webHooksConfig.MsTeams), + SendResolved: conversion.BoolValueToPointer(webHooksConfig.SendResolved), }) } receiverPayload.WebHookConfigs = &payloadWebHooksConfigs diff --git a/stackit/internal/services/observability/instance/resource_test.go b/stackit/internal/services/observability/instance/resource_test.go index 0c6a3aa5c..5e2f74fa2 100644 --- a/stackit/internal/services/observability/instance/resource_test.go +++ b/stackit/internal/services/observability/instance/resource_test.go @@ -24,6 +24,7 @@ func fixtureEmailConfigsModel() basetypes.ListValue { "auth_password": types.StringValue("password"), "auth_username": types.StringValue("username"), "from": types.StringValue("notification@example.com"), + "send_resolved": types.BoolValue(true), "smart_host": types.StringValue("smtp.example.com"), "to": types.StringValue("me@example.com"), }), @@ -33,9 +34,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"), + "send_resolved": types.BoolValue(true), }), }) } @@ -43,8 +45,9 @@ func fixtureOpsGenieConfigsModel() basetypes.ListValue { func fixtureWebHooksConfigsModel() basetypes.ListValue { return types.ListValueMust(types.ObjectType{AttrTypes: webHooksConfigsTypes}, []attr.Value{ types.ObjectValueMust(webHooksConfigsTypes, map[string]attr.Value{ - "url": types.StringValue("http://example.com"), - "ms_teams": types.BoolValue(true), + "url": types.StringValue("http://example.com"), + "ms_teams": types.BoolValue(true), + "send_resolved": types.BoolValue(true), }), }) } @@ -133,6 +136,7 @@ func fixtureEmailConfigsPayload() observability.CreateAlertConfigReceiverPayload AuthPassword: utils.Ptr("password"), AuthUsername: utils.Ptr("username"), From: utils.Ptr("notification@example.com"), + SendResolved: utils.Ptr(true), Smarthost: utils.Ptr("smtp.example.com"), To: utils.Ptr("me@example.com"), } @@ -140,16 +144,18 @@ 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"), + SendResolved: utils.Ptr(true), } } func fixtureWebHooksConfigsPayload() observability.CreateAlertConfigReceiverPayloadWebHookConfigsInner { return observability.CreateAlertConfigReceiverPayloadWebHookConfigsInner{ - Url: utils.Ptr("http://example.com"), - MsTeams: utils.Ptr(true), + Url: utils.Ptr("http://example.com"), + MsTeams: utils.Ptr(true), + SendResolved: utils.Ptr(true), } } @@ -213,6 +219,7 @@ func fixtureEmailConfigsResponse() observability.EmailConfig { AuthPassword: utils.Ptr("password"), AuthUsername: utils.Ptr("username"), From: utils.Ptr("notification@example.com"), + SendResolved: utils.Ptr(true), Smarthost: utils.Ptr("smtp.example.com"), To: utils.Ptr("me@example.com"), } @@ -220,16 +227,18 @@ 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"), + SendResolved: utils.Ptr(true), } } func fixtureWebHooksConfigsResponse() observability.WebHook { return observability.WebHook{ - Url: utils.Ptr("http://example.com"), - MsTeams: utils.Ptr(true), + Url: utils.Ptr("http://example.com"), + MsTeams: utils.Ptr(true), + SendResolved: utils.Ptr(true), } } diff --git a/stackit/internal/services/observability/observability_acc_test.go b/stackit/internal/services/observability/observability_acc_test.go index 95828c71a..17a00be0f 100644 --- a/stackit/internal/services/observability/observability_acc_test.go +++ b/stackit/internal/services/observability/observability_acc_test.go @@ -79,13 +79,16 @@ var testConfigVarsMax = config.Variables{ "auth_password": config.StringVariable("password"), "auth_username": config.StringVariable("username"), "email_from": config.StringVariable("aa@bb.ccc"), + "email_send_resolved": config.StringVariable("true"), "smart_host": config.StringVariable("smtp.gmail.com:587"), "email_to": config.StringVariable("bb@bb.ccc"), "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_send_resolved": config.StringVariable("false"), "webhook_configs_url": config.StringVariable("https://example.com"), "ms_teams": config.StringVariable("true"), + "webhook_configs_send_resolved": config.StringVariable("false"), "group_by": config.StringVariable("alertname"), "group_interval": config.StringVariable("10m"), "group_wait": config.StringVariable("1m"), diff --git a/stackit/internal/services/observability/testdata/resource-max.tf b/stackit/internal/services/observability/testdata/resource-max.tf index 385f070f2..922b5213d 100644 --- a/stackit/internal/services/observability/testdata/resource-max.tf +++ b/stackit/internal/services/observability/testdata/resource-max.tf @@ -21,13 +21,16 @@ variable "auth_identity" {} variable "auth_password" {} variable "auth_username" {} variable "email_from" {} +variable "email_send_resolved" {} variable "smart_host" {} variable "email_to" {} variable "opsgenie_api_key" {} variable "opsgenie_api_tags" {} variable "opsgenie_api_url" {} +variable "opsgenie_send_resolved" {} variable "webhook_configs_url" {} variable "ms_teams" {} +variable "webhook_configs_send_resolved" {} variable "group_by" {} variable "group_interval" {} variable "group_wait" {} @@ -110,6 +113,7 @@ resource "stackit_observability_instance" "instance" { from = var.email_from smart_host = var.smart_host to = var.email_to + send_resolved = var.email_send_resolved } ] opsgenie_configs = [ @@ -117,12 +121,14 @@ resource "stackit_observability_instance" "instance" { api_key = var.opsgenie_api_key tags = var.opsgenie_api_tags api_url = var.opsgenie_api_url + send_resolved = var.opsgenie_send_resolved } ] webhooks_configs = [ { url = var.webhook_configs_url ms_teams = var.ms_teams + send_resolved = var.webhook_configs_send_resolved } ] },