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

fix(multilocation_alert_condition): make violation_time_limit_seconds nearly consistent with its usage in nrql_alert_condition #2493

Merged
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
3 changes: 3 additions & 0 deletions newrelic/resource_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,6 @@ func selectAccountID(providerConfig *ProviderConfig, d *schema.ResourceData) int

return providerConfig.AccountID
}

var violationTimeLimitSecondsDefault = 259200
var violationTimeLimitSecondsMax = 2592000
4 changes: 2 additions & 2 deletions newrelic/resource_newrelic_nrql_alert_condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,12 @@ func resourceNewRelicNrqlAlertCondition() *schema.Resource {
"violation_time_limit_seconds": {
Type: schema.TypeInt,
Optional: true,
Default: 259200,
Default: violationTimeLimitSecondsDefault,
// Default value added as expected by the NerdGraph API to prevent discrepancies with `terraform plan`
// Reference : https://docs.newrelic.com/docs/alerts-applied-intelligence/new-relic-alerts/alert-violations/how-alert-condition-violations-are-closed/#time-limit
Description: "Sets a time limit, in seconds, that will automatically force-close a long-lasting incident after the time limit you select. Must be in the range of 300 to 2592000 (inclusive)",
ConflictsWith: []string{"violation_time_limit"},
ValidateFunc: validation.IntBetween(300, 2592000),
ValidateFunc: validation.IntBetween(300, violationTimeLimitSecondsMax),
},

"account_id": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/newrelic/newrelic-client-go/v2/pkg/errors"
)

// syntheticsMultiLocationConditionTermSchema returns the schema used for a critial or warning term priority.
// syntheticsMultiLocationConditionTermSchema returns the schema used for a critical or warning term priority.
func syntheticsMultiLocationConditionTermSchema() *schema.Resource {
return &schema.Resource{
Schema: map[string]*schema.Schema{
Expand Down Expand Up @@ -81,9 +81,18 @@ func resourceNewRelicSyntheticsMultiLocationAlertCondition() *schema.Resource {
},
"violation_time_limit_seconds": {
Type: schema.TypeInt,
Required: true,
ValidateFunc: validation.IntInSlice([]int{0, 3600, 7200, 14400, 28800, 43200, 86400}),
Description: "The maximum number of seconds an incident can remain open before being closed by the system. Must be one of: 0, 3600, 7200, 14400, 28800, 43200, 86400",
Optional: true,
ValidateFunc: validation.IntBetween(0, violationTimeLimitSecondsMax),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is supposed to be 300 - 2592000 as also specified in New Relic docs, but I've added 0 as the minimum as this resource is already in use with 0 as a valid value of violation_time_limit_seconds.

However, the current behaviour of the API is such that if 0 is given as a value against this argument, the API defaults it to 259200 seconds. This is why the below DiffSuppressFunc has been added.

Default: violationTimeLimitSecondsDefault,
Description: "Sets a time limit, in seconds, that will automatically force-close a long-lasting incident after the time limit you select. Must be in the range of 300 to 2592000 (inclusive)",
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
oldInt, _ := strconv.Atoi(old)
newInt, _ := strconv.Atoi(new)
if oldInt == violationTimeLimitSecondsDefault && newInt == 0 {
return true
}
return false
},
},
"entity_guid": {
Type: schema.TypeString,
Expand Down
12 changes: 6 additions & 6 deletions website/docs/r/synthetics_multilocation_alert_condition.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ resource "newrelic_synthetics_multilocation_alert_condition" "example" {
name = "Example condition"
runbook_url = "https://example.com"
enabled = true
violation_time_limit_seconds = "3600"
violation_time_limit_seconds = 3600

entities = [
newrelic_synthetics_monitor.monitor.id
Expand All @@ -57,14 +57,14 @@ The following arguments are supported:
* `policy_id` - (Required) The ID of the policy where this condition will be used.
* `runbook_url` - (Optional) Runbook URL to display in notifications.
* `enabled` - (Optional) Set whether to enable the alert condition. Defaults to true.
* `violation_time_limit_seconds` - (Required) The maximum number of seconds a violation can remain open before being closed by the system. Must be one of: 0, 3600, 7200, 14400, 28800, 43200, 86400.
* `violation_time_limit_seconds` - (Optional) The maximum number of seconds a violation can remain open before being closed by the system. The value must be between 300 seconds (5 minutes) to 2592000 seconds (30 days), both inclusive. Defaults to 259200 seconds (3 days) if this argument is not specified in the configuration, in accordance with the characteristics of this field in NerdGraph, as specified in the [docs](https://docs.newrelic.com/docs/alerts-applied-intelligence/new-relic-alerts/advanced-alerts/rest-api-alerts/alerts-conditions-api-field-names/#violation_time_limit_seconds).
* `entities` - (Required) The Monitor GUID's of the Synthetics monitors to alert on.
* `critical` - (Required) A condition term with the priority set to critical.
* `warning` - (Optional) A condition term with the priority set to warning.

```
Warning: This resource will use the account ID linked to your API key. At the moment it is not possible to dynamically set the account ID.
```

-> **WARNING:** This resource will use the account ID linked to your API key. At the moment it is not possible to dynamically set the account ID.


## Attributes Reference

Expand Down Expand Up @@ -120,7 +120,7 @@ resource "newrelic_synthetics_multilocation_alert_condition" "foo" {
name = "foo condition"
runbook_url = "https://example.com"
enabled = true
violation_time_limit_seconds = "3600"
violation_time_limit_seconds = 3600

entities = [
newrelic_synthetics_monitor.foo.id
Expand Down