From 4efdab4181cd2bfd243600def27f70f0580942a3 Mon Sep 17 00:00:00 2001 From: Mat Schaffer Date: Fri, 27 Jul 2018 17:17:56 +0900 Subject: Replace contact_id with contact_group This allows for multiple contacts per test. --- statuscake/resource_statuscaketest.go | 14 ++++++++------ statuscake/resource_statuscaketest_test.go | 21 +++++++++++---------- website/docs/r/test.html.markdown | 12 ++++++------ 3 files changed, 25 insertions(+), 22 deletions(-) diff --git a/statuscake/resource_statuscaketest.go b/statuscake/resource_statuscaketest.go index 866cdce..b0dc84f 100644 --- a/statuscake/resource_statuscaketest.go +++ b/statuscake/resource_statuscaketest.go @@ -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) diff --git a/statuscake/resource_statuscaketest_test.go b/statuscake/resource_statuscaketest_test.go index c10b5d3..0ea1e2b 100644 --- a/statuscake/resource_statuscaketest_test.go +++ b/statuscake/resource_statuscaketest_test.go @@ -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 } diff --git a/website/docs/r/test.html.markdown b/website/docs/r/test.html.markdown index 45e904a..9c1fb35 100644 --- a/website/docs/r/test.html.markdown +++ b/website/docs/r/test.html.markdown @@ -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. -- cgit v1.2.3