Skip to content
This repository has been archived by the owner on Jun 23, 2020. It is now read-only.

Commit

Permalink
Merge pull request newrelic#67 from kyeah/kev-synthetics-monitor
Browse files Browse the repository at this point in the history
Add newrelic_synthetics_monitor and script resources
  • Loading branch information
paultyng committed Mar 26, 2019
2 parents 3651ee8 + d6979ca commit ac32fcf
Show file tree
Hide file tree
Showing 18 changed files with 787 additions and 43 deletions.
63 changes: 63 additions & 0 deletions newrelic/data_source_newrelic_synthetics_monitor_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package newrelic

import (
"fmt"
"testing"

"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)

var (
expectedMonitorName string = fmt.Sprintf("tf-test-synthetic-%s", acctest.RandString(5))
)

func TestAccNewRelicSyntheticsMonitorDataSource_Basic(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCheckNewRelicSyntheticsDataSourceConfig(expectedMonitorName),
Check: resource.ComposeTestCheckFunc(
testAccNewRelicSyntheticsDataSource("data.newrelic_synthetics_monitor.bar"),
),
},
},
})
}

func testAccNewRelicSyntheticsDataSource(n string) resource.TestCheckFunc {
return func(s *terraform.State) error {
r := s.RootModule().Resources[n]
a := r.Primary.Attributes

if a["id"] == "" {
return fmt.Errorf("Expected to read synthetics monitor data from New Relic")
}

if a["name"] != expectedMonitorName {
return fmt.Errorf("Expected the synthetics monitor name to be: %s, but got: %s", expectedMonitorName, a["name"])
}
return nil
}
}

func testAccCheckNewRelicSyntheticsDataSourceConfig(name string) string {
return fmt.Sprintf(`
resource "newrelic_synthetics_monitor" "foo" {
name = "%[1]s"
type = "SIMPLE"
frequency = 15
status = "DISABLED"
locations = ["AWS_US_EAST_1"]
uri = "https://google.com"
}
data "newrelic_synthetics_monitor" "bar" {
name = "${newrelic_synthetics_monitor.foo.name}"
}
`, name)
}
10 changes: 6 additions & 4 deletions newrelic/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@ func Provider() terraform.ResourceProvider {
ResourcesMap: map[string]*schema.Resource{
"newrelic_alert_channel": resourceNewRelicAlertChannel(),
"newrelic_alert_condition": resourceNewRelicAlertCondition(),
"newrelic_nrql_alert_condition": resourceNewRelicNrqlAlertCondition(),
"newrelic_synthetics_alert_condition": resourceNewRelicSyntheticsAlertCondition(),
"newrelic_infra_alert_condition": resourceNewRelicInfraAlertCondition(),
"newrelic_alert_policy": resourceNewRelicAlertPolicy(),
"newrelic_alert_policy_channel": resourceNewRelicAlertPolicyChannel(),
"newrelic_alert_policy": resourceNewRelicAlertPolicy(),
"newrelic_dashboard": resourceNewRelicDashboard(),
"newrelic_infra_alert_condition": resourceNewRelicInfraAlertCondition(),
"newrelic_nrql_alert_condition": resourceNewRelicNrqlAlertCondition(),
"newrelic_synthetics_alert_condition": resourceNewRelicSyntheticsAlertCondition(),
"newrelic_synthetics_monitor": resourceNewRelicSyntheticsMonitor(),
"newrelic_synthetics_monitor_script": resourceNewRelicSyntheticsMonitorScript(),
},

ConfigureFunc: providerConfigure,
Expand Down
2 changes: 0 additions & 2 deletions newrelic/resource_newrelic_alert_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,5 @@ func resourceNewRelicAlertChannelDelete(d *schema.ResourceData, meta interface{}
return err
}

d.SetId("")

return nil
}
2 changes: 0 additions & 2 deletions newrelic/resource_newrelic_alert_condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,5 @@ func resourceNewRelicAlertConditionDelete(d *schema.ResourceData, meta interface
return err
}

d.SetId("")

return nil
}
2 changes: 0 additions & 2 deletions newrelic/resource_newrelic_alert_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,5 @@ func resourceNewRelicAlertPolicyDelete(d *schema.ResourceData, meta interface{})
return err
}

d.SetId("")

return nil
}
2 changes: 0 additions & 2 deletions newrelic/resource_newrelic_alert_policy_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,5 @@ func resourceNewRelicAlertPolicyChannelDelete(d *schema.ResourceData, meta inter
}
}

d.SetId("")

return nil
}
3 changes: 0 additions & 3 deletions newrelic/resource_newrelic_dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,14 +326,11 @@ func resourceNewRelicDashboardDelete(d *schema.ResourceData, meta interface{}) e

if err := client.DeleteDashboard(id); err != nil {
if err == newrelic.ErrNotFound {
d.SetId("")
return nil
}
return err
}

d.SetId("")

return nil
}

Expand Down
2 changes: 0 additions & 2 deletions newrelic/resource_newrelic_infra_alert_condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,6 @@ func resourceNewRelicInfraAlertConditionDelete(d *schema.ResourceData, meta inte
return err
}

d.SetId("")

return nil
}

Expand Down
2 changes: 0 additions & 2 deletions newrelic/resource_newrelic_nrql_alert_condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,5 @@ func resourceNewRelicNrqlAlertConditionDelete(d *schema.ResourceData, meta inter
return err
}

d.SetId("")

return nil
}
2 changes: 0 additions & 2 deletions newrelic/resource_newrelic_synthetics_alert_condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,5 @@ func resourceNewRelicSyntheticsAlertConditionDelete(d *schema.ResourceData, meta
return err
}

d.SetId("")

return nil
}
62 changes: 40 additions & 22 deletions newrelic/resource_newrelic_synthetics_alert_condition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,24 @@ func TestAccNewRelicSyntheticsAlertCondition_Basic(t *testing.T) {
testAccCheckNewRelicSyntheticsAlertConditionExists("newrelic_synthetics_alert_condition.foo"),
resource.TestCheckResourceAttr(
"newrelic_synthetics_alert_condition.foo", "name", fmt.Sprintf("tf-test-%s", rName)),
resource.TestCheckResourceAttr(
"newrelic_synthetics_alert_condition.foo", "policy_id", "0"),
resource.TestCheckResourceAttr(
"newrelic_synthetics_alert_condition.foo", "monitor_id", "derp"),
resource.TestCheckResourceAttr(
"newrelic_synthetics_alert_condition.foo", "runbook_url", "www.example.com"),
resource.TestCheckResourceAttr(
"newrelic_synthetics_alert_condition.foo", "enabled", "true"),
),
},
{
Config: testAccCheckNewRelicSyntheticsAlertConditionUpdated(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckNewRelicSyntheticsAlertConditionExists("newrelic_synthetics_alert_condition.foo"),
resource.TestCheckResourceAttr(
"newrelic_synthetics_alert_condition.foo", "name", fmt.Sprintf("tf-test-%s", rName)),
resource.TestCheckResourceAttr(
"newrelic_synthetics_alert_condition.foo", "runbook_url", "www.example2.com"),
resource.TestCheckResourceAttr(
"newrelic_synthetics_alert_condition.foo", "enabled", "false"),
),
},
},
})
}
Expand Down Expand Up @@ -96,41 +104,51 @@ func testAccCheckNewRelicSyntheticsAlertConditionExists(n string) resource.TestC
func testAccCheckNewRelicSyntheticsAlertConditionConfig(rName string) string {
return fmt.Sprintf(`
data "newrelic_synthetics_monitor" "bar" {
name = "%[2]s"
resource "newrelic_synthetics_monitor" "bar" {
name = "tf-test-synthetic-%[1]s"
type = "SIMPLE"
frequency = 15
status = "DISABLED"
locations = ["AWS_US_EAST_1"]
uri = "https://google.com"
}
resource "newrelic_alert_policy" "foo" {
name = "tf-test-%[1]s"
name = "tf-test-%[1]s"
}
resource "newrelic_synthetics_alert_condition" "foo" {
policy_id = "${newrelic_alert_policy.foo.id}"
policy_id = "${newrelic_alert_policy.foo.id}"
name = "tf-test-%[1]s"
monitor_id = "${data.newrelic_synthetics_monitor.bar.id}"
runbook_url = "https://foo.example.com"
monitor_id = "${newrelic_synthetics_monitor.bar.id}"
runbook_url = "www.example.com"
enabled = "true"
}
`, rName, testAccExpectedApplicationName)
`, rName)
}

func testAccCheckNewRelicSyntheticsAlertConditionConfigUpdated(rName string) string {
func testAccCheckNewRelicSyntheticsAlertConditionUpdated(rName string) string {
return fmt.Sprintf(`
data "newrelic_synthetics_monitor" "bar" {
name = "%[2]s"
resource "newrelic_synthetics_monitor" "bar" {
name = "tf-test-synthetic-%[1]s"
type = "SIMPLE"
frequency = 15
status = "DISABLED"
locations = ["AWS_US_EAST_1"]
uri = "https://google.com"
}
resource "newrelic_alert_policy" "foo" {
name = "tf-test-%[1]s"
name = "tf-test-%[1]s"
}
resource "newrelic_synthetics_alert_condition" "foo" {
policy_id = "${newrelic_alert_policy.foo.id}"
name = "tf-test-updated-%[1]s"
monitor_id = "${data.newrelic_synthetics_monitor.bar.id}"
runbook_url = "https://bar.example.com"
policy_id = "${newrelic_alert_policy.foo.id}"
name = "tf-test-%[1]s"
monitor_id = "${newrelic_synthetics_monitor.bar.id}"
runbook_url = "www.example2.com"
enabled = "false"
}
`, rName, testAccExpectedApplicationName)
`, rName)
}
Loading

0 comments on commit ac32fcf

Please sign in to comment.