]> git.immae.eu Git - github/fretlink/terraform-provider-statuscake.git/commitdiff
Replace contact_id with contact_group
authorMat Schaffer <mat@schaffer.me>
Fri, 27 Jul 2018 08:17:56 +0000 (17:17 +0900)
committerMat Schaffer <mat@schaffer.me>
Fri, 27 Jul 2018 08:17:56 +0000 (17:17 +0900)
This allows for multiple contacts per test.

statuscake/resource_statuscaketest.go
statuscake/resource_statuscaketest_test.go
website/docs/r/test.html.markdown

index 866cdce435480f7b9bb1d3049cf7411a0feb2ae9..b0dc84f2b5b2ae3ea8486483677cc96de19db69e 100644 (file)
@@ -51,9 +51,11 @@ func resourceStatusCakeTest() *schema.Resource {
                                Required: true,
                        },
 
-                       "contact_id": {
-                               Type:     schema.TypeInt,
+                       "contact_group": {
+                               Type:     schema.TypeSet,
+                               Elem:     &schema.Schema{Type: schema.TypeString},
                                Optional: true,
+                               Set:      schema.HashString,
                        },
 
                        "check_rate": {
@@ -223,7 +225,7 @@ func CreateTest(d *schema.ResourceData, meta interface{}) error {
                TestType:       d.Get("test_type").(string),
                Paused:         d.Get("paused").(bool),
                Timeout:        d.Get("timeout").(int),
-               ContactID:      d.Get("contact_id").(int),
+               ContactGroup:   castSetToSliceStrings(d.Get("contact_group").(*schema.Set).List()),
                Confirmation:   d.Get("confirmations").(int),
                Port:           d.Get("port").(int),
                TriggerRate:    d.Get("trigger_rate").(int),
@@ -312,7 +314,7 @@ func ReadTest(d *schema.ResourceData, meta interface{}) error {
        d.Set("test_type", testResp.TestType)
        d.Set("paused", testResp.Paused)
        d.Set("timeout", testResp.Timeout)
-       d.Set("contact_id", testResp.ContactID)
+       d.Set("contact_group", testResp.ContactGroup)
        d.Set("confirmations", testResp.Confirmation)
        d.Set("port", testResp.Port)
        d.Set("trigger_rate", testResp.TriggerRate)
@@ -356,8 +358,8 @@ 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("contact_group"); ok {
+               test.ContactGroup = castSetToSliceStrings(v.(*schema.Set).List())
        }
        if v, ok := d.GetOk("test_type"); ok {
                test.TestType = v.(string)
index c10b5d3b70fc53363ce741296c067fa4c4570808..0ea1e2b5553c80e79ade3f7c00124f02d89ed72d 100644 (file)
@@ -72,7 +72,6 @@ func TestAccStatusCake_withUpdate(t *testing.T) {
                                        resource.TestCheckResourceAttr("statuscake_test.google", "check_rate", "500"),
                                        resource.TestCheckResourceAttr("statuscake_test.google", "paused", "true"),
                                        resource.TestCheckResourceAttr("statuscake_test.google", "timeout", "40"),
-                                       resource.TestCheckResourceAttr("statuscake_test.google", "contact_id", "0"),
                                        resource.TestCheckResourceAttr("statuscake_test.google", "confirmations", "0"),
                                        resource.TestCheckResourceAttr("statuscake_test.google", "trigger_rate", "20"),
                                        resource.TestCheckResourceAttr("statuscake_test.google", "custom_header", "{ \"Content-Type\": \"application/x-www-form-urlencoded\" }"),
@@ -159,8 +158,13 @@ func testAccTestCheckAttributes(rn string, test *statuscake.Test) resource.TestC
                                err = check(key, value, strconv.FormatBool(test.Paused))
                        case "timeout":
                                err = check(key, value, strconv.Itoa(test.Timeout))
-                       case "contact_id":
-                               err = check(key, value, strconv.Itoa(test.ContactID))
+                       case "contact_group":
+                               for _, tv := range test.ContactGroup {
+                                       err = check(key, value, tv)
+                                       if err != nil {
+                                               return err
+                                       }
+                               }
                        case "confirmations":
                                err = check(key, value, strconv.Itoa(test.Confirmation))
                        case "trigger_rate":
@@ -214,13 +218,10 @@ func testAccTestCheckDestroy(test *statuscake.Test) resource.TestCheckFunc {
 }
 
 func interpolateTerraformTemplate(template string) string {
-       testContactGroupId := 43402
+       testContactGroupId := "43402"
 
        if v := os.Getenv("STATUSCAKE_TEST_CONTACT_GROUP_ID"); v != "" {
-               id, err := strconv.Atoi(v)
-               if err == nil {
-                       testContactGroupId = id
-               }
+               testContactGroupId = v
        }
 
        return fmt.Sprintf(template, testContactGroupId)
@@ -233,7 +234,7 @@ resource "statuscake_test" "google" {
        test_type = "HTTP"
        check_rate = 300
        timeout = 10
-       contact_id = %d
+       contact_group = ["%s"]
        confirmations = 1
        trigger_rate = 10
 }
@@ -277,7 +278,7 @@ resource "statuscake_test" "google" {
        test_type = "TCP"
        check_rate = 300
        timeout = 10
-       contact_id = %d
+       contact_group = ["%s"]
        confirmations = 1
        port = 80
 }
index 45e904a0317a005402155390ebc9fcc58e6b6289..9c1fb35819e1bf20cd01dfeeeb46e8050de03d08 100644 (file)
@@ -14,11 +14,11 @@ The test resource allows StatusCake tests to be managed by Terraform.
 
 ```hcl
 resource "statuscake_test" "google" {
-  website_name = "google.com"
-  website_url  = "www.google.com"
-  test_type    = "HTTP"
-  check_rate   = 300
-  contact_id   = 12345
+  website_name  = "google.com"
+  website_url   = "www.google.com"
+  test_type     = "HTTP"
+  check_rate    = 300
+  contact_group = ["12345"]
 }
 ```
 
@@ -29,7 +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.
+* `contact_group` - (Optional) Set test contact groups, must be array of strings. 
 * `test_type` - (Required) The type of Test. Either HTTP, TCP, PING, or DNS
 * `paused` - (Optional) Whether or not the test is paused. Defaults to false.
 * `timeout` - (Optional) The timeout of the test in seconds.