From 2de5770d8e7bbe640a6aff572385b7354ce35b13 Mon Sep 17 00:00:00 2001 From: Adam Szymanski Date: Wed, 6 Mar 2024 22:36:14 +0100 Subject: [PATCH] Fix tests --- nobl9/resource_alert_policy.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/nobl9/resource_alert_policy.go b/nobl9/resource_alert_policy.go index 9e39136d..bd16fd52 100644 --- a/nobl9/resource_alert_policy.go +++ b/nobl9/resource_alert_policy.go @@ -58,6 +58,10 @@ func resourceAlertPolicy() *schema.Resource { Type: schema.TypeString, Optional: true, Description: "Indicates how long a given condition needs to be valid to mark the condition as true.", + DiffSuppressFunc: func(k, oldValue, newValue string, d *schema.ResourceData) bool { + // To be backward compatible with lasts for with default=0m that was set before. + return oldValue == "0m" && newValue == "" + }, }, "alerting_window": { Type: schema.TypeString, @@ -193,8 +197,10 @@ func marshalAlertConditions(d *schema.ResourceData) []v1alphaAlertPolicy.AlertCo lastsFor := condition["lasts_for"].(string) alertingWindow := condition["alerting_window"].(string) - if lastsFor == "" && alertingWindow == "" { - lastsFor = "0m" + if lastsFor == "0m" && alertingWindow != "" { + // To be backward compatible with lasts for with default=0m that was set before, when user + // wants to switch to use alerting_window instead of lasts_for. + lastsFor = "" } resultConditions[i] = v1alphaAlertPolicy.AlertCondition{