diff --git a/newrelic/data_source_newrelic_synthetics_monitor_test.go b/newrelic/data_source_newrelic_synthetics_monitor_test.go new file mode 100644 index 000000000..01d7282a8 --- /dev/null +++ b/newrelic/data_source_newrelic_synthetics_monitor_test.go @@ -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) +} diff --git a/newrelic/resource_newrelic_synthetics_alert_condition_test.go b/newrelic/resource_newrelic_synthetics_alert_condition_test.go index 47b3d781d..72814f1ff 100644 --- a/newrelic/resource_newrelic_synthetics_alert_condition_test.go +++ b/newrelic/resource_newrelic_synthetics_alert_condition_test.go @@ -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"), + ), + }, }, }) } @@ -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) }