diff --git a/newrelic/resource_helpers.go b/newrelic/resource_helpers.go index 5133abb83..03084fbb9 100644 --- a/newrelic/resource_helpers.go +++ b/newrelic/resource_helpers.go @@ -122,3 +122,6 @@ func selectAccountID(providerConfig *ProviderConfig, d *schema.ResourceData) int return providerConfig.AccountID } + +var violationTimeLimitSecondsDefault = 259200 +var violationTimeLimitSecondsMax = 2592000 diff --git a/newrelic/resource_newrelic_nrql_alert_condition.go b/newrelic/resource_newrelic_nrql_alert_condition.go index aba26058d..cd1c04c50 100644 --- a/newrelic/resource_newrelic_nrql_alert_condition.go +++ b/newrelic/resource_newrelic_nrql_alert_condition.go @@ -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": { diff --git a/newrelic/resource_newrelic_synthetics_multilocation_alert_condition.go b/newrelic/resource_newrelic_synthetics_multilocation_alert_condition.go index dcabfde63..6eb8770f4 100644 --- a/newrelic/resource_newrelic_synthetics_multilocation_alert_condition.go +++ b/newrelic/resource_newrelic_synthetics_multilocation_alert_condition.go @@ -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{ @@ -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, diff --git a/website/docs/r/synthetics_multilocation_alert_condition.markdown b/website/docs/r/synthetics_multilocation_alert_condition.markdown index 27b858c23..ca94e8a87 100644 --- a/website/docs/r/synthetics_multilocation_alert_condition.markdown +++ b/website/docs/r/synthetics_multilocation_alert_condition.markdown @@ -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 @@ -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 @@ -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