Skip to content

Commit

Permalink
fix(multilocation_alert_condition): make violation_time_limit_seconds…
Browse files Browse the repository at this point in the history
… consistent with nrql_alert_condition
  • Loading branch information
pranav-new-relic authored and sanderblue committed Oct 23, 2023
1 parent cbed7ad commit 158d4a4
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
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),
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

0 comments on commit 158d4a4

Please sign in to comment.