From 63f96f3cd1ea6ee4b16c470d93ed3d79e171fc08 Mon Sep 17 00:00:00 2001 From: Aashirwadjain Date: Tue, 17 Dec 2024 12:34:20 +0530 Subject: [PATCH 01/12] feat(alert-muting-rule): add end_behaviour attribute to muting rule schema --- newrelic/resource_newrelic_alert_muting_rule.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/newrelic/resource_newrelic_alert_muting_rule.go b/newrelic/resource_newrelic_alert_muting_rule.go index 3521e3769..e87c8dcf3 100644 --- a/newrelic/resource_newrelic_alert_muting_rule.go +++ b/newrelic/resource_newrelic_alert_muting_rule.go @@ -183,6 +183,12 @@ func resourceNewRelicAlertMutingRule() *schema.Resource { Elem: scheduleSchema(), Description: "The time window when the MutingRule should actively mute incidents.", }, + "end_behaviour": { + Type: schema.TypeString, + Optional: true, + Description: "The action when the muting rule window is ended or disabled.", + ValidateFunc: validation.StringInSlice([]string{"CLOSE_ISSUES_ON_INACTIVE", "DO_NOTHING"}, false), + }, }, } } From 57456e63aa1a32e522776f8494a38987a62a25f2 Mon Sep 17 00:00:00 2001 From: Aashirwadjain Date: Tue, 17 Dec 2024 12:39:16 +0530 Subject: [PATCH 02/12] feat(alert-muting-rule): add end_behaviour attribute to create/update handlers in alert muting rule --- .../structures_newrelic_alert_muting_rule.go | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/newrelic/structures_newrelic_alert_muting_rule.go b/newrelic/structures_newrelic_alert_muting_rule.go index b4d80f1ed..c6dbe0bee 100644 --- a/newrelic/structures_newrelic_alert_muting_rule.go +++ b/newrelic/structures_newrelic_alert_muting_rule.go @@ -18,6 +18,10 @@ func expandMutingRuleCreateInput(d *schema.ResourceData) (alerts.MutingRuleCreat Description: d.Get("description").(string), } + if endBehaviour, ok := d.GetOk("end_behaviour"); ok { + createInput.ActionOnMutingRuleWindowEnded = expandMutingRuleEndBehaviour(endBehaviour.(string)) + } + if e, ok := d.GetOk("condition"); ok { createInput.Condition = expandMutingRuleConditionGroup(e.([]interface{})[0].(map[string]interface{})) } @@ -33,6 +37,17 @@ func expandMutingRuleCreateInput(d *schema.ResourceData) (alerts.MutingRuleCreat return createInput, nil } +func expandMutingRuleEndBehaviour(endBehaviour string) alerts.AlertsActionOnMutingRuleWindowEnded { + switch endBehaviour { + case string(alerts.AlertsActionOnMutingRuleWindowEndedTypes.CLOSE_ISSUES_ON_INACTIVE): + return alerts.AlertsActionOnMutingRuleWindowEndedTypes.CLOSE_ISSUES_ON_INACTIVE + case string(alerts.AlertsActionOnMutingRuleWindowEndedTypes.DO_NOTHING): + return alerts.AlertsActionOnMutingRuleWindowEndedTypes.DO_NOTHING + default: + return alerts.AlertsActionOnMutingRuleWindowEndedTypes.CLOSE_ISSUES_ON_INACTIVE + } +} + func expandMutingRuleCreateSchedule(cfg map[string]interface{}) (alerts.MutingRuleScheduleCreateInput, error) { schedule := alerts.MutingRuleScheduleCreateInput{} @@ -199,6 +214,10 @@ func expandMutingRuleUpdateInput(d *schema.ResourceData) (alerts.MutingRuleUpdat Description: d.Get("description").(string), } + if endBehaviour, ok := d.GetOk("end_behaviour"); ok { + updateInput.ActionOnMutingRuleWindowEnded = expandMutingRuleEndBehaviour(endBehaviour.(string)) + } + if e, ok := d.GetOk("condition"); ok { x := expandMutingRuleConditionGroup(e.([]interface{})[0].(map[string]interface{})) @@ -270,6 +289,7 @@ func flattenMutingRule(mutingRule *alerts.MutingRule, d *schema.ResourceData) er configuredCondition := x.([]interface{}) _ = d.Set("enabled", mutingRule.Enabled) + _ = d.Set("end_behaviour", mutingRule.ActionOnMutingRuleWindowEnded) err := d.Set("condition", flattenMutingRuleConditionGroup(mutingRule.Condition, configuredCondition)) if err != nil { return nil From 7ff91ed5e7fa5de5f9d8b730120c548c37fe8188 Mon Sep 17 00:00:00 2001 From: Aashirwadjain Date: Tue, 17 Dec 2024 17:44:55 +0530 Subject: [PATCH 03/12] feat(alert-muting-rule): add newrelic-client-go commit as dependency for terraform provider --- go.mod | 2 ++ go.sum | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index 95d8a0335..0768ba3fa 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,8 @@ go 1.22 toolchain go1.22.6 +replace github.com/newrelic/newrelic-client-go/v2 => github.com/newrelic/newrelic-client-go/v2 v2.51.4-0.20241217120708-22dfc1bcd16c + require ( github.com/hashicorp/terraform-plugin-sdk/v2 v2.26.1 github.com/mitchellh/go-homedir v1.1.0 diff --git a/go.sum b/go.sum index e5471e668..f490c8ace 100644 --- a/go.sum +++ b/go.sum @@ -270,8 +270,8 @@ github.com/newrelic/go-agent/v3 v3.30.0 h1:ZXHCT/Cot4iIPwcegCZURuRQOsfmGA6wilW+S github.com/newrelic/go-agent/v3 v3.30.0/go.mod h1:9utrgxlSryNqRrTvII2XBL+0lpofXbqXApvVWPpbzUg= github.com/newrelic/go-insights v1.0.3 h1:zSNp1CEZnXktzSIEsbHJk8v6ZihdPFP2WsO/fzau3OQ= github.com/newrelic/go-insights v1.0.3/go.mod h1:A20BoT8TNkqPGX2nS/Z2fYmKl3Cqa3iKZd4whzedCY4= -github.com/newrelic/newrelic-client-go/v2 v2.51.3 h1:Bu/cUs6nfMjQMPBcxxHt4Xm30tKDT7ttYy/XRDsWP6Y= -github.com/newrelic/newrelic-client-go/v2 v2.51.3/go.mod h1:+RRjI3nDGWT3kLm9Oi3QxpBm70uu8q1upEHBVWCZFpo= +github.com/newrelic/newrelic-client-go/v2 v2.51.4-0.20241217120708-22dfc1bcd16c h1:U4xKoQkH6OJQqAXxD0eLHO6rzVcIS19fSIsI0DSdzXE= +github.com/newrelic/newrelic-client-go/v2 v2.51.4-0.20241217120708-22dfc1bcd16c/go.mod h1:+RRjI3nDGWT3kLm9Oi3QxpBm70uu8q1upEHBVWCZFpo= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw= github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA= From 8e35db12f6af2e5599f26027b791dc1885617e6f Mon Sep 17 00:00:00 2001 From: Aashirwadjain Date: Thu, 19 Dec 2024 12:51:20 +0530 Subject: [PATCH 04/12] feat(alert-muting-rule): update end_behaviour attribute to action_on_muting_rule_window_ended and validation method --- newrelic/resource_newrelic_alert_muting_rule.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/newrelic/resource_newrelic_alert_muting_rule.go b/newrelic/resource_newrelic_alert_muting_rule.go index e87c8dcf3..427fd2ffa 100644 --- a/newrelic/resource_newrelic_alert_muting_rule.go +++ b/newrelic/resource_newrelic_alert_muting_rule.go @@ -3,6 +3,7 @@ package newrelic import ( "context" "fmt" + "github.com/newrelic/newrelic-client-go/v2/pkg/alerts" "log" "regexp" "time" @@ -183,11 +184,17 @@ func resourceNewRelicAlertMutingRule() *schema.Resource { Elem: scheduleSchema(), Description: "The time window when the MutingRule should actively mute incidents.", }, - "end_behaviour": { - Type: schema.TypeString, - Optional: true, - Description: "The action when the muting rule window is ended or disabled.", - ValidateFunc: validation.StringInSlice([]string{"CLOSE_ISSUES_ON_INACTIVE", "DO_NOTHING"}, false), + "action_on_muting_rule_window_ended": { + Type: schema.TypeString, + Optional: true, + Description: "The action when the muting rule window is ended or disabled.", + ValidateFunc: validation.StringInSlice( + []string{ + string(alerts.AlertsActionOnMutingRuleWindowEndedTypes.CLOSE_ISSUES_ON_INACTIVE), + string(alerts.AlertsActionOnMutingRuleWindowEndedTypes.DO_NOTHING), + }, + false, + ), }, }, } From f7a1410997dec63d2c50452b20d4c1087cd79d85 Mon Sep 17 00:00:00 2001 From: Aashirwadjain Date: Thu, 19 Dec 2024 13:00:24 +0530 Subject: [PATCH 05/12] feat(alert-muting-rule): remove expandMutingRuleEndBehaviour and implement typecasting --- .../structures_newrelic_alert_muting_rule.go | 21 +++++-------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/newrelic/structures_newrelic_alert_muting_rule.go b/newrelic/structures_newrelic_alert_muting_rule.go index c6dbe0bee..ca80009da 100644 --- a/newrelic/structures_newrelic_alert_muting_rule.go +++ b/newrelic/structures_newrelic_alert_muting_rule.go @@ -18,8 +18,8 @@ func expandMutingRuleCreateInput(d *schema.ResourceData) (alerts.MutingRuleCreat Description: d.Get("description").(string), } - if endBehaviour, ok := d.GetOk("end_behaviour"); ok { - createInput.ActionOnMutingRuleWindowEnded = expandMutingRuleEndBehaviour(endBehaviour.(string)) + if actionOnMutingRuleWindowEnded, ok := d.GetOk("action_on_muting_rule_window_ended"); ok { + createInput.ActionOnMutingRuleWindowEnded = alerts.AlertsActionOnMutingRuleWindowEnded(actionOnMutingRuleWindowEnded.(string)) } if e, ok := d.GetOk("condition"); ok { @@ -37,17 +37,6 @@ func expandMutingRuleCreateInput(d *schema.ResourceData) (alerts.MutingRuleCreat return createInput, nil } -func expandMutingRuleEndBehaviour(endBehaviour string) alerts.AlertsActionOnMutingRuleWindowEnded { - switch endBehaviour { - case string(alerts.AlertsActionOnMutingRuleWindowEndedTypes.CLOSE_ISSUES_ON_INACTIVE): - return alerts.AlertsActionOnMutingRuleWindowEndedTypes.CLOSE_ISSUES_ON_INACTIVE - case string(alerts.AlertsActionOnMutingRuleWindowEndedTypes.DO_NOTHING): - return alerts.AlertsActionOnMutingRuleWindowEndedTypes.DO_NOTHING - default: - return alerts.AlertsActionOnMutingRuleWindowEndedTypes.CLOSE_ISSUES_ON_INACTIVE - } -} - func expandMutingRuleCreateSchedule(cfg map[string]interface{}) (alerts.MutingRuleScheduleCreateInput, error) { schedule := alerts.MutingRuleScheduleCreateInput{} @@ -214,8 +203,8 @@ func expandMutingRuleUpdateInput(d *schema.ResourceData) (alerts.MutingRuleUpdat Description: d.Get("description").(string), } - if endBehaviour, ok := d.GetOk("end_behaviour"); ok { - updateInput.ActionOnMutingRuleWindowEnded = expandMutingRuleEndBehaviour(endBehaviour.(string)) + if actionOnMutingRuleWindowEnded, ok := d.GetOk("action_on_muting_rule_window_ended"); ok { + updateInput.ActionOnMutingRuleWindowEnded = alerts.AlertsActionOnMutingRuleWindowEnded(actionOnMutingRuleWindowEnded.(string)) } if e, ok := d.GetOk("condition"); ok { @@ -289,7 +278,7 @@ func flattenMutingRule(mutingRule *alerts.MutingRule, d *schema.ResourceData) er configuredCondition := x.([]interface{}) _ = d.Set("enabled", mutingRule.Enabled) - _ = d.Set("end_behaviour", mutingRule.ActionOnMutingRuleWindowEnded) + _ = d.Set("action_on_muting_rule_window_ended", mutingRule.ActionOnMutingRuleWindowEnded) err := d.Set("condition", flattenMutingRuleConditionGroup(mutingRule.Condition, configuredCondition)) if err != nil { return nil From 470f47a1367cf5b97b794e50ed3f05a68514bfe3 Mon Sep 17 00:00:00 2001 From: Aashirwadjain Date: Thu, 19 Dec 2024 20:11:09 +0530 Subject: [PATCH 06/12] feat(alert-muting-rule): add validation on action_on_muting_rule_window_ended --- newrelic/structures_newrelic_alert_muting_rule.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/newrelic/structures_newrelic_alert_muting_rule.go b/newrelic/structures_newrelic_alert_muting_rule.go index ca80009da..089976fb1 100644 --- a/newrelic/structures_newrelic_alert_muting_rule.go +++ b/newrelic/structures_newrelic_alert_muting_rule.go @@ -278,7 +278,11 @@ func flattenMutingRule(mutingRule *alerts.MutingRule, d *schema.ResourceData) er configuredCondition := x.([]interface{}) _ = d.Set("enabled", mutingRule.Enabled) - _ = d.Set("action_on_muting_rule_window_ended", mutingRule.ActionOnMutingRuleWindowEnded) + + if _, ok := d.GetOk("action_on_muting_rule_window_ended"); ok { + _ = d.Set("action_on_muting_rule_window_ended", mutingRule.ActionOnMutingRuleWindowEnded) + } + err := d.Set("condition", flattenMutingRuleConditionGroup(mutingRule.Condition, configuredCondition)) if err != nil { return nil From 7581c4db5ec7d20ef7df0a35bb84c08facea7922 Mon Sep 17 00:00:00 2001 From: Aashirwadjain Date: Fri, 20 Dec 2024 12:58:46 +0530 Subject: [PATCH 07/12] feat(alert-muting-rule): add actionOnMutingRuleWindowEnded attribute to alert muting rule test cases --- newrelic/resource_newrelic_alert_muting_rule_test.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/newrelic/resource_newrelic_alert_muting_rule_test.go b/newrelic/resource_newrelic_alert_muting_rule_test.go index f42946c26..e1d4c77fa 100644 --- a/newrelic/resource_newrelic_alert_muting_rule_test.go +++ b/newrelic/resource_newrelic_alert_muting_rule_test.go @@ -78,14 +78,14 @@ func TestAccNewRelicAlertMutingRule_Basic(t *testing.T) { Steps: []resource.TestStep{ // Test: Create { - Config: testAccNewRelicAlertMutingRuleBasic(rName, "new muting rule", "product", "EQUALS", "APM"), + Config: testAccNewRelicAlertMutingRuleBasic(rName, "new muting rule", "product", "EQUALS", "APM", "CLOSE_ISSUES_ON_INACTIVE"), Check: resource.ComposeTestCheckFunc( testAccCheckNewRelicAlertMutingRuleExists(resourceName), ), }, // Test: Update { - Config: testAccNewRelicAlertMutingRuleBasic(rName, "second muting rule", "conditionType", "NOT_EQUALS", "baseline"), + Config: testAccNewRelicAlertMutingRuleBasic(rName, "second muting rule", "conditionType", "NOT_EQUALS", "baseline", "CLOSE_ISSUES_ON_INACTIVE"), Check: resource.ComposeTestCheckFunc( testAccCheckNewRelicAlertMutingRuleExists(resourceName), ), @@ -154,6 +154,7 @@ func TestAccNewRelicAlertMutingRule_WithSchedule(t *testing.T) { "conditionName", "EQUALS", "My cool condition", + "CLOSE_ISSUES_ON_INACTIVE", ), Check: resource.ComposeTestCheckFunc( testAccCheckNewRelicAlertMutingRuleExists(resourceName), @@ -215,6 +216,7 @@ func testAccNewRelicAlertMutingRuleBasic( attribute string, operator string, values string, + actionOnMutingRuleWindowEnded string, ) string { return fmt.Sprintf(` @@ -235,6 +237,7 @@ resource "newrelic_alert_muting_rule" "foo" { } operator = "AND" } + action_on_muting_rule_window_ended = "%[6]%" } `, name, description, attribute, operator, values) } From 15800e04af6e81bd8eec849853b32c69b4f54f79 Mon Sep 17 00:00:00 2001 From: Aashirwadjain Date: Fri, 20 Dec 2024 13:03:18 +0530 Subject: [PATCH 08/12] feat(alert-muting-rule): add action_on_muting_rule_window_ended attribute to newrelic_alert_muting_rule documentation --- website/docs/r/alert_muting_rule.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/alert_muting_rule.html.markdown b/website/docs/r/alert_muting_rule.html.markdown index dc9eabd47..5b424e02a 100644 --- a/website/docs/r/alert_muting_rule.html.markdown +++ b/website/docs/r/alert_muting_rule.html.markdown @@ -54,7 +54,7 @@ The following arguments are supported: * `name` - The name of the MutingRule. * `description` - The description of the MutingRule. * `schedule` - (Optional) Specify a schedule for enabling the MutingRule. See [Schedule](#schedule) below for details - + * `action_on_muting_rule_window_ended` - (Optional) The action when the muting rule window is ended or disabled. Valid values are `CLOSE_ISSUES_ON_INACTIVE`, `DO_NOTHING` ### Nested `condition` blocks From c25bc36366e76f92f70f9a2094d4baa6244ff888 Mon Sep 17 00:00:00 2001 From: Aashirwadjain Date: Fri, 20 Dec 2024 16:00:50 +0530 Subject: [PATCH 09/12] feat(alert-muting-rule): add example usage for action_on_muting_rule_window_ended attribute in docs --- website/docs/r/alert_muting_rule.html.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/website/docs/r/alert_muting_rule.html.markdown b/website/docs/r/alert_muting_rule.html.markdown index 5b424e02a..5e931083c 100644 --- a/website/docs/r/alert_muting_rule.html.markdown +++ b/website/docs/r/alert_muting_rule.html.markdown @@ -42,6 +42,7 @@ resource "newrelic_alert_muting_rule" "foo" { weekly_repeat_days = ["MONDAY", "WEDNESDAY", "FRIDAY"] repeat_count = 42 } + action_on_muting_rule_window_ended = "CLOSE_ISSUES_ON_INACTIVE" } ``` From a5c696cdd27ed7b12914914d15cfccfdda968b96 Mon Sep 17 00:00:00 2001 From: Aashirwadjain Date: Fri, 20 Dec 2024 22:26:26 +0530 Subject: [PATCH 10/12] feat(alert-muting-rule): add actionOnMutingRuleWindowEnded to testAccNewRelicAlertMutingRuleBasic method --- newrelic/resource_newrelic_alert_muting_rule_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/newrelic/resource_newrelic_alert_muting_rule_test.go b/newrelic/resource_newrelic_alert_muting_rule_test.go index e1d4c77fa..c8e63f424 100644 --- a/newrelic/resource_newrelic_alert_muting_rule_test.go +++ b/newrelic/resource_newrelic_alert_muting_rule_test.go @@ -237,9 +237,9 @@ resource "newrelic_alert_muting_rule" "foo" { } operator = "AND" } - action_on_muting_rule_window_ended = "%[6]%" + action_on_muting_rule_window_ended = "%[6]s" } -`, name, description, attribute, operator, values) +`, name, description, attribute, operator, values, actionOnMutingRuleWindowEnded) } func testAccNewRelicAlertMutingRuleBadInput( From f62a74b99677885781e5a2c2e2feb12b04126866 Mon Sep 17 00:00:00 2001 From: Aashirwadjain Date: Fri, 20 Dec 2024 23:30:34 +0530 Subject: [PATCH 11/12] feat(alert-muting-rule): add TestAccNewRelicAlertMutingRule_EndBehaviourInput test method --- ...esource_newrelic_alert_muting_rule_test.go | 67 ++++++++++++++++++- 1 file changed, 64 insertions(+), 3 deletions(-) diff --git a/newrelic/resource_newrelic_alert_muting_rule_test.go b/newrelic/resource_newrelic_alert_muting_rule_test.go index c8e63f424..95b8ff55b 100644 --- a/newrelic/resource_newrelic_alert_muting_rule_test.go +++ b/newrelic/resource_newrelic_alert_muting_rule_test.go @@ -78,14 +78,46 @@ func TestAccNewRelicAlertMutingRule_Basic(t *testing.T) { Steps: []resource.TestStep{ // Test: Create { - Config: testAccNewRelicAlertMutingRuleBasic(rName, "new muting rule", "product", "EQUALS", "APM", "CLOSE_ISSUES_ON_INACTIVE"), + Config: testAccNewRelicAlertMutingRuleBasic(rName, "new muting rule", "product", "EQUALS", "APM"), Check: resource.ComposeTestCheckFunc( testAccCheckNewRelicAlertMutingRuleExists(resourceName), ), }, // Test: Update { - Config: testAccNewRelicAlertMutingRuleBasic(rName, "second muting rule", "conditionType", "NOT_EQUALS", "baseline", "CLOSE_ISSUES_ON_INACTIVE"), + Config: testAccNewRelicAlertMutingRuleBasic(rName, "second muting rule", "conditionType", "NOT_EQUALS", "baseline"), + Check: resource.ComposeTestCheckFunc( + testAccCheckNewRelicAlertMutingRuleExists(resourceName), + ), + }, + // // Test: Import + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true}, + }, + }) +} + +func TestAccNewRelicAlertMutingRule_EndBehaviourInput(t *testing.T) { + resourceName := "newrelic_alert_muting_rule.foo" + rName := acctest.RandString(5) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckNewRelicAlertMutingRuleDestroy, + Steps: []resource.TestStep{ + // Test: Create + { + Config: testAccNewRelicAlertMutingRuleEndBehaviourInput(rName, "new muting rule", "product", "EQUALS", "APM", "CLOSE_ISSUES_ON_INACTIVE"), + Check: resource.ComposeTestCheckFunc( + testAccCheckNewRelicAlertMutingRuleExists(resourceName), + ), + }, + // Test: Update + { + Config: testAccNewRelicAlertMutingRuleEndBehaviourInput(rName, "second muting rule", "conditionType", "NOT_EQUALS", "baseline", "CLOSE_ISSUES_ON_INACTIVE"), Check: resource.ComposeTestCheckFunc( testAccCheckNewRelicAlertMutingRuleExists(resourceName), ), @@ -154,7 +186,6 @@ func TestAccNewRelicAlertMutingRule_WithSchedule(t *testing.T) { "conditionName", "EQUALS", "My cool condition", - "CLOSE_ISSUES_ON_INACTIVE", ), Check: resource.ComposeTestCheckFunc( testAccCheckNewRelicAlertMutingRuleExists(resourceName), @@ -216,6 +247,36 @@ func testAccNewRelicAlertMutingRuleBasic( attribute string, operator string, values string, +) string { + return fmt.Sprintf(` + +resource "newrelic_alert_muting_rule" "foo" { + name = "tf-test-%[1]s" + enabled = true + description = "%[2]s" + condition { + conditions { + attribute = "%[3]s" + operator = "EQUALS" + values = ["%[5]s"] + } + conditions { + attribute = "conditionType" + operator = "%[4]s" + values = ["static"] + } + operator = "AND" + } +} +`, name, description, attribute, operator, values) +} + +func testAccNewRelicAlertMutingRuleEndBehaviourInput( + name string, + description string, + attribute string, + operator string, + values string, actionOnMutingRuleWindowEnded string, ) string { return fmt.Sprintf(` From e3a9b3ee431cf228f352eab4e51766510ccd40e4 Mon Sep 17 00:00:00 2001 From: Aashirwadjain Date: Tue, 31 Dec 2024 16:26:51 +0530 Subject: [PATCH 12/12] feat(alert-muting-rule): update validation on action_on_muting_rule_window_ended attribute --- newrelic/resource_newrelic_alert_muting_rule.go | 1 + newrelic/structures_newrelic_alert_muting_rule.go | 5 +---- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/newrelic/resource_newrelic_alert_muting_rule.go b/newrelic/resource_newrelic_alert_muting_rule.go index 427fd2ffa..994e2d08b 100644 --- a/newrelic/resource_newrelic_alert_muting_rule.go +++ b/newrelic/resource_newrelic_alert_muting_rule.go @@ -187,6 +187,7 @@ func resourceNewRelicAlertMutingRule() *schema.Resource { "action_on_muting_rule_window_ended": { Type: schema.TypeString, Optional: true, + Computed: true, Description: "The action when the muting rule window is ended or disabled.", ValidateFunc: validation.StringInSlice( []string{ diff --git a/newrelic/structures_newrelic_alert_muting_rule.go b/newrelic/structures_newrelic_alert_muting_rule.go index 089976fb1..29681cb72 100644 --- a/newrelic/structures_newrelic_alert_muting_rule.go +++ b/newrelic/structures_newrelic_alert_muting_rule.go @@ -278,10 +278,7 @@ func flattenMutingRule(mutingRule *alerts.MutingRule, d *schema.ResourceData) er configuredCondition := x.([]interface{}) _ = d.Set("enabled", mutingRule.Enabled) - - if _, ok := d.GetOk("action_on_muting_rule_window_ended"); ok { - _ = d.Set("action_on_muting_rule_window_ended", mutingRule.ActionOnMutingRuleWindowEnded) - } + _ = d.Set("action_on_muting_rule_window_ended", mutingRule.ActionOnMutingRuleWindowEnded) err := d.Set("condition", flattenMutingRuleConditionGroup(mutingRule.Condition, configuredCondition)) if err != nil {