]> git.immae.eu Git - github/fretlink/terraform-provider-statuscake.git/commitdiff
Adding ability to add and update contact groups using the terraform statuscake provider
authorLee Johnson <leejohnson@ijoinsolutions.com>
Fri, 10 Jun 2016 16:38:56 +0000 (12:38 -0400)
committerLee Johnson <leejohnson@ijoinsolutions.com>
Fri, 10 Jun 2016 16:38:56 +0000 (12:38 -0400)
resource_statuscaketest.go
resource_statuscaketest_test.go

index 7f5ff67bb3ce7423367f8fd9fc03c463bb6c0e1c..d403848c042fdd2452f0afcf21ec3443e5f14e33 100644 (file)
@@ -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)
        }
index bbc6932a8b2d0b7a98227476eea34c61658dc287..4123ac633df2080444569edb79e7e328335d63cf 100644 (file)
@@ -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") + `
+       }`