Skip to content

Commit

Permalink
Merge pull request #144 from NicoleYson/bug/since-value-validation
Browse files Browse the repository at this point in the history
Modifies since_value's validation to match rest API's requirements
  • Loading branch information
paultyng authored Jul 10, 2019
2 parents 632f62f + 5930ed0 commit 8aae17f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
17 changes: 14 additions & 3 deletions newrelic/resource_newrelic_nrql_alert_condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package newrelic
import (
"fmt"
"log"
"strconv"

"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
Expand Down Expand Up @@ -50,9 +51,19 @@ func resourceNewRelicNrqlAlertCondition() *schema.Resource {
Required: true,
},
"since_value": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{"1", "2", "3", "4", "5"}, false),
Type: schema.TypeString,
Required: true,
ValidateFunc: func(val interface{}, key string) (warns []string, errs []error) {
valueString := val.(string)
v, err := strconv.Atoi(valueString)
if err != nil {
errs = append(errs, fmt.Errorf("Error converting string to int: %#v", err))
}
if v < 1 || v > 20 {
errs = append(errs, fmt.Errorf("%q must be between 0 and 20 inclusive, got: %d", key, v))
}
return
},
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion newrelic/resource_newrelic_nrql_alert_condition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestAccNewRelicNrqlAlertCondition_Basic(t *testing.T) {
resource.TestCheckResourceAttr(
"newrelic_nrql_alert_condition.foo", "nrql.0.query", "SELECT uniqueCount(hostname) FROM ComputeSample"),
resource.TestCheckResourceAttr(
"newrelic_nrql_alert_condition.foo", "nrql.0.since_value", "5"),
"newrelic_nrql_alert_condition.foo", "nrql.0.since_value", "20"),
),
},
{
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/nrql_alert_condition.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ The `term` mapping supports the following arguments:
The `nrql` attribute supports the following arguments:

* `query` - (Required) The NRQL query to execute for the condition.
* `since_value` - (Required) The value to be used in the `SINCE <X> MINUTES AGO` clause for the NRQL query. Must be: `1`, `2`, `3`, `4`, or `5`.
* `since_value` - (Required) The value to be used in the `SINCE <X> MINUTES AGO` clause for the NRQL query. Must be between `1` and `20`.

## Attributes Reference

Expand Down

0 comments on commit 8aae17f

Please sign in to comment.