Skip to content

Commit

Permalink
Fix alert_delay update in Update Rule API (elastic#859)
Browse files Browse the repository at this point in the history
* First commit.

* changelog
  • Loading branch information
adcoelho authored and kjwardy committed Oct 21, 2024
1 parent 013e714 commit ce72b5f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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))
Expand Down
15 changes: 13 additions & 2 deletions internal/clients/kibana/alerting.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions internal/kibana/alerting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
),
},
},
Expand Down Expand Up @@ -639,7 +639,7 @@ resource "elasticstack_kibana_alerting_rule" "test_rule" {
}
}
alert_delay = 4
alert_delay = 10
}
`, name)
}
Expand Down

0 comments on commit ce72b5f

Please sign in to comment.