From ea613cef96b870f114b65e736489c97f962a65fe Mon Sep 17 00:00:00 2001 From: Lee Johnson Date: Fri, 10 Jun 2016 12:38:56 -0400 Subject: [PATCH 1/3] Adding ability to add and update contact groups using the terraform statuscake provider --- .../statuscake/resource_statuscaketest.go | 9 ++ .../resource_statuscaketest_test.go | 83 +++++++++++++++++++ .../DreamItGetIT/statuscake/tests.go | 2 +- 3 files changed, 93 insertions(+), 1 deletion(-) diff --git a/builtin/providers/statuscake/resource_statuscaketest.go b/builtin/providers/statuscake/resource_statuscaketest.go index 7f5ff67bb..d403848c0 100644 --- a/builtin/providers/statuscake/resource_statuscaketest.go +++ b/builtin/providers/statuscake/resource_statuscaketest.go @@ -33,6 +33,11 @@ func resourceStatusCakeTest() *schema.Resource { Required: true, }, + "contact_id": &schema.Schema{ + Type: schema.TypeInt, + Optional: true, + }, + "check_rate": &schema.Schema{ Type: schema.TypeInt, Optional: true, @@ -65,6 +70,7 @@ func CreateTest(d *schema.ResourceData, meta interface{}) error { WebsiteURL: d.Get("website_url").(string), TestType: d.Get("test_type").(string), CheckRate: d.Get("check_rate").(int), + ContactID: d.Get("contact_id").(int), } log.Printf("[DEBUG] Creating new StatusCake Test: %s", d.Get("website_name").(string)) @@ -142,6 +148,9 @@ func getStatusCakeTestInput(d *schema.ResourceData) *statuscake.Test { if v, ok := d.GetOk("check_rate"); ok { test.CheckRate = v.(int) } + if v, ok := d.GetOk("contact_id"); ok { + test.ContactID = v.(int) + } if v, ok := d.GetOk("test_type"); ok { test.TestType = v.(string) } diff --git a/builtin/providers/statuscake/resource_statuscaketest_test.go b/builtin/providers/statuscake/resource_statuscaketest_test.go index bbc6932a8..4123ac633 100644 --- a/builtin/providers/statuscake/resource_statuscaketest_test.go +++ b/builtin/providers/statuscake/resource_statuscaketest_test.go @@ -2,6 +2,7 @@ package statuscake import ( "fmt" + "os" "strconv" "testing" @@ -10,6 +11,19 @@ import ( "github.com/hashicorp/terraform/terraform" ) +// check to ensure that contact group id is provided before running +// tests on it. +func testAccContactGroupPreCheck(t *testing.T, testAlt bool) { + if v := os.Getenv("CONTACT_GROUP"); v == "" { + t.Fatal("CONTACT_GROUP must be set for contact group acceptance tests") + } + if testAlt { + if v := os.Getenv("ALT_CONTACT_GROUP"); v == "" { + t.Fatal("ALT_CONTACT_GROUP must be set for contact group acceptance tests") + } + } +} + func TestAccStatusCake_basic(t *testing.T) { var test statuscake.Test @@ -55,6 +69,57 @@ func TestAccStatusCake_withUpdate(t *testing.T) { }) } +func TestAccStatusCake_contactGroup_basic(t *testing.T) { + var test statuscake.Test + + resource.Test(t, resource.TestCase{ + PreCheck: func() { + testAccPreCheck(t) + testAccContactGroupPreCheck(t, false) + }, + Providers: testAccProviders, + CheckDestroy: testAccTestCheckDestroy(&test), + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccTestConfig_contactGroup, + Check: resource.ComposeTestCheckFunc( + testAccTestCheckExists("statuscake_test.google", &test), + ), + }, + }, + }) +} + +func TestAccStatusCake_contactGroup_withUpdate(t *testing.T) { + var test statuscake.Test + var altContactGroup = os.Getenv("ALT_CONTACT_GROUP") + + resource.Test(t, resource.TestCase{ + PreCheck: func() { + testAccPreCheck(t) + testAccContactGroupPreCheck(t, true) + }, + Providers: testAccProviders, + CheckDestroy: testAccTestCheckDestroy(&test), + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccTestConfig_contactGroup, + Check: resource.ComposeTestCheckFunc( + testAccTestCheckExists("statuscake_test.google", &test), + ), + }, + // make sure to creat + resource.TestStep{ + Config: testAccTestConfig_contactGroup_update, + Check: resource.ComposeTestCheckFunc( + testAccTestCheckExists("statuscake_test.google", &test), + resource.TestCheckResourceAttr("statuscake_test.google", "contact_id", altContactGroup), + ), + }, + }, + }) +} + func testAccTestCheckExists(rn string, test *statuscake.Test) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[rn] @@ -113,3 +178,21 @@ resource "statuscake_test" "google" { paused = true } ` + +var testAccTestConfig_contactGroup string = `` + + `resource "statuscake_test" "google" { + website_name = "google.com" + website_url = "www.google.com" + test_type = "HTTP" + check_rate = 300 + contact_id = ` + os.Getenv("CONTACT_GROUP") + ` + }` + +var testAccTestConfig_contactGroup_update string = `` + + `resource "statuscake_test" "google" { + website_name = "google.com" + website_url = "www.google.com" + test_type = "HTTP" + check_rate = 300 + contact_id = ` + os.Getenv("ALT_CONTACT_GROUP") + ` + }` diff --git a/vendor/github.com/DreamItGetIT/statuscake/tests.go b/vendor/github.com/DreamItGetIT/statuscake/tests.go index 1870a8e6d..4053e53e0 100644 --- a/vendor/github.com/DreamItGetIT/statuscake/tests.go +++ b/vendor/github.com/DreamItGetIT/statuscake/tests.go @@ -28,7 +28,7 @@ type Test struct { Port int `json:"Port" querystring:"Port"` // Contact group ID - will return int of contact group used else 0 - ContactID int `json:"ContactID"` + ContactID int `json:"ContactID" querystring:"ContactGroup"` // Current status at last test Status string `json:"Status"` From 3e4f797b77a3ecec9fd8bbfc03fced4e805746e4 Mon Sep 17 00:00:00 2001 From: Lee Johnson Date: Fri, 10 Jun 2016 13:37:44 -0400 Subject: [PATCH 2/3] Updating the documentation on the website source to reflect the addition. --- website/source/docs/providers/statuscake/index.html.markdown | 1 + website/source/docs/providers/statuscake/r/test.html.markdown | 2 ++ 2 files changed, 3 insertions(+) diff --git a/website/source/docs/providers/statuscake/index.html.markdown b/website/source/docs/providers/statuscake/index.html.markdown index 150b36aad..443e892d6 100644 --- a/website/source/docs/providers/statuscake/index.html.markdown +++ b/website/source/docs/providers/statuscake/index.html.markdown @@ -34,5 +34,6 @@ resource "statuscake_test" "google" { website_url = "www.google.com" test_type = "HTTP" check_rate = 300 + contact_id = 12345 } ``` diff --git a/website/source/docs/providers/statuscake/r/test.html.markdown b/website/source/docs/providers/statuscake/r/test.html.markdown index d2d1572ed..4ad378a52 100644 --- a/website/source/docs/providers/statuscake/r/test.html.markdown +++ b/website/source/docs/providers/statuscake/r/test.html.markdown @@ -18,6 +18,7 @@ resource "statuscake_test" "google" { website_url = "www.google.com" test_type = "HTTP" check_rate = 300 + contact_id = 12345 } ``` @@ -28,6 +29,7 @@ The following arguments are supported: * `website_name` - (Required) This is the name of the test and the website to be monitored. * `website_url` - (Required) The URL of the website to be monitored * `check_rate` - (Optional) Test check rate in seconds. Defaults to 300 +* `contact_id` - (Optional) The id of the contact group to be add to the test. Each test can have only one. * `test_type` - (Required) The type of Test. Either HTTP or TCP * `paused` - (Optional) Whether or not the test is paused. Defaults to false. * `timeout` - (Optional) The timeout of the test in seconds. From d203dcf6a5750ea71013c81df379d7a476924581 Mon Sep 17 00:00:00 2001 From: Lee Johnson Date: Tue, 29 Nov 2016 16:03:58 -0500 Subject: [PATCH 3/3] simplifying tests by removing tests and test data that is no longer needed --- .../statuscake/resource_statuscaketest.go | 5 -- .../resource_statuscaketest_test.go | 83 ------------------- 2 files changed, 88 deletions(-) diff --git a/builtin/providers/statuscake/resource_statuscaketest.go b/builtin/providers/statuscake/resource_statuscaketest.go index 389a7d686..a1d735415 100644 --- a/builtin/providers/statuscake/resource_statuscaketest.go +++ b/builtin/providers/statuscake/resource_statuscaketest.go @@ -58,10 +58,6 @@ func resourceStatusCakeTest() *schema.Resource { Type: schema.TypeInt, Computed: true, }, - "contact_id": &schema.Schema{ - Type: schema.TypeInt, - Optional: true, - }, }, } } @@ -74,7 +70,6 @@ func CreateTest(d *schema.ResourceData, meta interface{}) error { WebsiteURL: d.Get("website_url").(string), TestType: d.Get("test_type").(string), CheckRate: d.Get("check_rate").(int), - ContactID: d.Get("contact_id").(int), } log.Printf("[DEBUG] Creating new StatusCake Test: %s", d.Get("website_name").(string)) diff --git a/builtin/providers/statuscake/resource_statuscaketest_test.go b/builtin/providers/statuscake/resource_statuscaketest_test.go index 236b790c8..bec1a4546 100644 --- a/builtin/providers/statuscake/resource_statuscaketest_test.go +++ b/builtin/providers/statuscake/resource_statuscaketest_test.go @@ -2,7 +2,6 @@ package statuscake import ( "fmt" - "os" "strconv" "testing" @@ -11,19 +10,6 @@ import ( "github.com/hashicorp/terraform/terraform" ) -// check to ensure that contact group id is provided before running -// tests on it. -func testAccContactGroupPreCheck(t *testing.T, testAlt bool) { - if v := os.Getenv("CONTACT_GROUP"); v == "" { - t.Fatal("CONTACT_GROUP must be set for contact group acceptance tests") - } - if testAlt { - if v := os.Getenv("ALT_CONTACT_GROUP"); v == "" { - t.Fatal("ALT_CONTACT_GROUP must be set for contact group acceptance tests") - } - } -} - func TestAccStatusCake_basic(t *testing.T) { var test statuscake.Test @@ -70,57 +56,6 @@ func TestAccStatusCake_withUpdate(t *testing.T) { }) } -func TestAccStatusCake_contactGroup_basic(t *testing.T) { - var test statuscake.Test - - resource.Test(t, resource.TestCase{ - PreCheck: func() { - testAccPreCheck(t) - testAccContactGroupPreCheck(t, false) - }, - Providers: testAccProviders, - CheckDestroy: testAccTestCheckDestroy(&test), - Steps: []resource.TestStep{ - resource.TestStep{ - Config: testAccTestConfig_contactGroup, - Check: resource.ComposeTestCheckFunc( - testAccTestCheckExists("statuscake_test.google", &test), - ), - }, - }, - }) -} - -func TestAccStatusCake_contactGroup_withUpdate(t *testing.T) { - var test statuscake.Test - var altContactGroup = os.Getenv("ALT_CONTACT_GROUP") - - resource.Test(t, resource.TestCase{ - PreCheck: func() { - testAccPreCheck(t) - testAccContactGroupPreCheck(t, true) - }, - Providers: testAccProviders, - CheckDestroy: testAccTestCheckDestroy(&test), - Steps: []resource.TestStep{ - resource.TestStep{ - Config: testAccTestConfig_contactGroup, - Check: resource.ComposeTestCheckFunc( - testAccTestCheckExists("statuscake_test.google", &test), - ), - }, - // make sure to creat - resource.TestStep{ - Config: testAccTestConfig_contactGroup_update, - Check: resource.ComposeTestCheckFunc( - testAccTestCheckExists("statuscake_test.google", &test), - resource.TestCheckResourceAttr("statuscake_test.google", "contact_id", altContactGroup), - ), - }, - }, - }) -} - func testAccTestCheckExists(rn string, test *statuscake.Test) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[rn] @@ -181,21 +116,3 @@ resource "statuscake_test" "google" { contact_id = 23456 } ` - -var testAccTestConfig_contactGroup string = `` + - `resource "statuscake_test" "google" { - website_name = "google.com" - website_url = "www.google.com" - test_type = "HTTP" - check_rate = 300 - contact_id = ` + os.Getenv("CONTACT_GROUP") + ` - }` - -var testAccTestConfig_contactGroup_update string = `` + - `resource "statuscake_test" "google" { - website_name = "google.com" - website_url = "www.google.com" - test_type = "HTTP" - check_rate = 300 - contact_id = ` + os.Getenv("ALT_CONTACT_GROUP") + ` - }`