From ce72b5f410b7dbde25872663adb17228940301c7 Mon Sep 17 00:00:00 2001 From: Antonio Date: Mon, 21 Oct 2024 11:17:58 +0200 Subject: [PATCH] Fix `alert_delay` update in Update Rule API (#859) * First commit. * changelog --- CHANGELOG.md | 1 + internal/clients/kibana/alerting.go | 15 +++++++++++++-- internal/kibana/alerting_test.go | 4 ++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d325dc7..33988980 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## [Unreleased] +- Fix bug updating alert delay ([#859](https://github.com/elastic/terraform-provider-elasticstack/pull/859)) - Support updating `elasticstack_elasticsearch_security_api_key` when supported by the backing cluster ([#843](https://github.com/elastic/terraform-provider-elasticstack/pull/843)) - Fix validation of `throttle`, and `interval` attributes in `elasticstack_kibana_alerting_rule` allowing all Elastic duration values ([#846](https://github.com/elastic/terraform-provider-elasticstack/pull/846)) - Fix boolean setting parsing for `elasticstack_elasticsearch_indices` data source. ([#842](https://github.com/elastic/terraform-provider-elasticstack/pull/842)) diff --git a/internal/clients/kibana/alerting.go b/internal/clients/kibana/alerting.go index 5a1fe698..0eea03d0 100644 --- a/internal/clients/kibana/alerting.go +++ b/internal/clients/kibana/alerting.go @@ -219,6 +219,16 @@ func UpdateAlertingRule(ctx context.Context, apiClient ApiClient, rule models.Al ctxWithAuth := apiClient.SetAlertingAuthContext(ctx) + var alertDelay *alerting.AlertDelay + + if alerting.IsNil(rule.AlertDelay) { + alertDelay = nil + } else { + alertDelay = &alerting.AlertDelay{ + Active: *rule.AlertDelay, + } + } + reqModel := alerting.UpdateRuleRequest{ Actions: ruleActionsToActionsInner((rule.Actions)), Name: rule.Name, @@ -227,8 +237,9 @@ func UpdateAlertingRule(ctx context.Context, apiClient ApiClient, rule models.Al Schedule: alerting.Schedule{ Interval: &rule.Schedule.Interval, }, - Tags: rule.Tags, - Throttle: *alerting.NewNullableString(rule.Throttle), + Tags: rule.Tags, + Throttle: *alerting.NewNullableString(rule.Throttle), + AlertDelay: alertDelay, } req := client.UpdateRule(ctxWithAuth, rule.RuleID, rule.SpaceID).KbnXsrf("true").UpdateRuleRequest(reqModel) diff --git a/internal/kibana/alerting_test.go b/internal/kibana/alerting_test.go index 3f894fb2..412687f5 100644 --- a/internal/kibana/alerting_test.go +++ b/internal/kibana/alerting_test.go @@ -179,7 +179,7 @@ func TestAccResourceAlertingRule(t *testing.T) { resource.TestCheckResourceAttr("elasticstack_kibana_alerting_rule.test_rule", "actions.0.frequency.0.summary", "true"), resource.TestCheckResourceAttr("elasticstack_kibana_alerting_rule.test_rule", "actions.0.frequency.0.notify_when", "onActionGroupChange"), resource.TestCheckResourceAttr("elasticstack_kibana_alerting_rule.test_rule", "actions.0.frequency.0.throttle", "10m"), - resource.TestCheckResourceAttr("elasticstack_kibana_alerting_rule.test_rule", "alert_delay", "4"), + resource.TestCheckResourceAttr("elasticstack_kibana_alerting_rule.test_rule", "alert_delay", "10"), ), }, }, @@ -639,7 +639,7 @@ resource "elasticstack_kibana_alerting_rule" "test_rule" { } } - alert_delay = 4 + alert_delay = 10 } `, name) }