Skip to content

Commit

Permalink
Merge pull request paultyng#70 from sgsiebers/issues-3
Browse files Browse the repository at this point in the history
paultyng#3 Make resource_newrelic_alert_condition enabled status configurable
  • Loading branch information
paultyng authored Feb 11, 2019
2 parents e3d9dbb + 1278d4b commit 94745b2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
8 changes: 7 additions & 1 deletion newrelic/resource_newrelic_alert_condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ func resourceNewRelicAlertCondition() *schema.Resource {
Type: schema.TypeString,
Required: true,
},
"enabled": {
Type: schema.TypeBool,
Optional: true,
Default: true,
},
"type": {
Type: schema.TypeString,
Required: true,
Expand Down Expand Up @@ -200,7 +205,7 @@ func buildAlertConditionStruct(d *schema.ResourceData) *newrelic.AlertCondition
condition := newrelic.AlertCondition{
Type: d.Get("type").(string),
Name: d.Get("name").(string),
Enabled: true,
Enabled: d.Get("enabled").(bool),
Entities: entities,
Metric: d.Get("metric").(string),
Terms: terms,
Expand Down Expand Up @@ -245,6 +250,7 @@ func readAlertConditionStruct(condition *newrelic.AlertCondition, d *schema.Reso

d.Set("policy_id", policyID)
d.Set("name", condition.Name)
d.Set("enabled", condition.Enabled)
d.Set("type", condition.Type)
d.Set("metric", condition.Metric)
d.Set("runbook_url", condition.RunbookURL)
Expand Down
9 changes: 9 additions & 0 deletions newrelic/resource_newrelic_alert_condition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ func TestAccNewRelicAlertCondition_Basic(t *testing.T) {
"newrelic_alert_condition.foo", "name", fmt.Sprintf("tf-test-%s", rName)),
resource.TestCheckResourceAttr(
"newrelic_alert_condition.foo", "type", "apm_app_metric"),
resource.TestCheckResourceAttr(
"newrelic_alert_condition.foo", "enabled", "false"),
resource.TestCheckResourceAttr(
"newrelic_alert_condition.foo", "runbook_url", "https://foo.example.com"),
resource.TestCheckResourceAttr(
Expand All @@ -48,6 +50,8 @@ func TestAccNewRelicAlertCondition_Basic(t *testing.T) {
testAccCheckNewRelicAlertConditionExists("newrelic_alert_condition.foo"),
resource.TestCheckResourceAttr(
"newrelic_alert_condition.foo", "name", fmt.Sprintf("tf-test-updated-%s", rName)),
resource.TestCheckResourceAttr(
"newrelic_alert_condition.foo", "enabled", "true"),
resource.TestCheckResourceAttr(
"newrelic_alert_condition.foo", "runbook_url", "https://bar.example.com"),
resource.TestCheckResourceAttr(
Expand Down Expand Up @@ -83,6 +87,8 @@ func TestAccNewRelicAlertCondition_ZeroThreshold(t *testing.T) {
testAccCheckNewRelicAlertConditionExists("newrelic_alert_condition.foo"),
resource.TestCheckResourceAttr(
"newrelic_alert_condition.foo", "name", fmt.Sprintf("tf-test-%s", rName)),
resource.TestCheckResourceAttr(
"newrelic_alert_condition.foo", "enabled", "false"),
resource.TestCheckResourceAttr(
"newrelic_alert_condition.foo", "type", "apm_app_metric"),
resource.TestCheckResourceAttr(
Expand Down Expand Up @@ -202,6 +208,7 @@ resource "newrelic_alert_condition" "foo" {
policy_id = "${newrelic_alert_policy.foo.id}"
name = "tf-test-%[1]s"
enabled = false
type = "apm_app_metric"
entities = ["${data.newrelic_application.app.id}"]
metric = "apdex"
Expand Down Expand Up @@ -233,6 +240,7 @@ resource "newrelic_alert_condition" "foo" {
policy_id = "${newrelic_alert_policy.foo.id}"
name = "tf-test-updated-%[1]s"
enabled = true
type = "apm_app_metric"
entities = ["${data.newrelic_application.app.id}"]
metric = "apdex"
Expand Down Expand Up @@ -264,6 +272,7 @@ resource "newrelic_alert_condition" "foo" {
policy_id = "${newrelic_alert_policy.foo.id}"
name = "tf-test-%[1]s"
enabled = false
type = "apm_app_metric"
entities = ["${data.newrelic_application.app.id}"]
metric = "apdex"
Expand Down

0 comments on commit 94745b2

Please sign in to comment.