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

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
6 changes: 6 additions & 0 deletions newrelic/resource_newrelic_alert_muting_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@ func resourceNewRelicAlertMutingRule() *schema.Resource {
Elem: scheduleSchema(),
Description: "The time window when the MutingRule should actively mute incidents.",
},
"end_behaviour": {
Aashirwadjain marked this conversation as resolved.
Show resolved Hide resolved
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),
},
Aashirwadjain marked this conversation as resolved.
Show resolved Hide resolved
},
}
}
Expand Down
20 changes: 20 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 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{}))
}
Expand All @@ -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
}
}

Aashirwadjain marked this conversation as resolved.
Show resolved Hide resolved
func expandMutingRuleCreateSchedule(cfg map[string]interface{}) (alerts.MutingRuleScheduleCreateInput, error) {
schedule := alerts.MutingRuleScheduleCreateInput{}

Expand Down Expand Up @@ -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{}))

Expand Down Expand Up @@ -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
Expand Down
Loading