Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(alert_muting_rule): Add action_on_muting_rule_window_ended attribute in newrelic_alert_muting_rule Terraform Resource #2783

Merged
merged 13 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
14 changes: 14 additions & 0 deletions newrelic/resource_newrelic_alert_muting_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package newrelic
import (
"context"
"fmt"
"github.com/newrelic/newrelic-client-go/v2/pkg/alerts"
"log"
"regexp"
"time"
Expand Down Expand Up @@ -183,6 +184,19 @@ func resourceNewRelicAlertMutingRule() *schema.Resource {
Elem: scheduleSchema(),
Description: "The time window when the MutingRule should actively mute incidents.",
},
"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{
string(alerts.AlertsActionOnMutingRuleWindowEndedTypes.CLOSE_ISSUES_ON_INACTIVE),
string(alerts.AlertsActionOnMutingRuleWindowEndedTypes.DO_NOTHING),
},
false,
),
},
},
}
}
Expand Down
64 changes: 64 additions & 0 deletions newrelic/resource_newrelic_alert_muting_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,38 @@ func TestAccNewRelicAlertMutingRule_Basic(t *testing.T) {
})
}

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),
),
},
// // Test: Import
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true},
},
})
}

func TestAccNewRelicAlertMutingRule_BadInput(t *testing.T) {
rName := acctest.RandString(5)

Expand Down Expand Up @@ -239,6 +271,38 @@ resource "newrelic_alert_muting_rule" "foo" {
`, name, description, attribute, operator, values)
}

func testAccNewRelicAlertMutingRuleEndBehaviourInput(
name string,
description string,
attribute string,
operator string,
values string,
actionOnMutingRuleWindowEnded 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"
}
action_on_muting_rule_window_ended = "%[6]s"
}
`, name, description, attribute, operator, values, actionOnMutingRuleWindowEnded)
}

func testAccNewRelicAlertMutingRuleBadInput(
name string,
description string,
Expand Down
10 changes: 10 additions & 0 deletions newrelic/structures_newrelic_alert_muting_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ func expandMutingRuleCreateInput(d *schema.ResourceData) (alerts.MutingRuleCreat
Description: d.Get("description").(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 {
createInput.Condition = expandMutingRuleConditionGroup(e.([]interface{})[0].(map[string]interface{}))
}
Expand Down Expand Up @@ -199,6 +203,10 @@ func expandMutingRuleUpdateInput(d *schema.ResourceData) (alerts.MutingRuleUpdat
Description: d.Get("description").(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 {
x := expandMutingRuleConditionGroup(e.([]interface{})[0].(map[string]interface{}))

Expand Down Expand Up @@ -270,6 +278,8 @@ 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)
Aashirwadjain marked this conversation as resolved.
Show resolved Hide resolved

err := d.Set("condition", flattenMutingRuleConditionGroup(mutingRule.Condition, configuredCondition))
if err != nil {
return nil
Expand Down
3 changes: 2 additions & 1 deletion website/docs/r/alert_muting_rule.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
```

Expand All @@ -54,7 +55,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`
Aashirwadjain marked this conversation as resolved.
Show resolved Hide resolved

### Nested `condition` blocks

Expand Down
Loading