aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMat Schaffer <mat@schaffer.me>2018-07-27 17:17:56 +0900
committerMat Schaffer <mat@schaffer.me>2018-07-27 17:17:56 +0900
commit4efdab4181cd2bfd243600def27f70f0580942a3 (patch)
tree99c7425a606bde644c5a924d158cbbf237130b52
parentbc2bde6b20d0b6a7a0e1edd0b6a4e726c446d7c6 (diff)
downloadterraform-provider-statuscake-4efdab4181cd2bfd243600def27f70f0580942a3.tar.gz
terraform-provider-statuscake-4efdab4181cd2bfd243600def27f70f0580942a3.tar.zst
terraform-provider-statuscake-4efdab4181cd2bfd243600def27f70f0580942a3.zip
Replace contact_id with contact_group
This allows for multiple contacts per test.
-rw-r--r--statuscake/resource_statuscaketest.go14
-rw-r--r--statuscake/resource_statuscaketest_test.go21
-rw-r--r--website/docs/r/test.html.markdown12
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 {
51 Required: true, 51 Required: true,
52 }, 52 },
53 53
54 "contact_id": { 54 "contact_group": {
55 Type: schema.TypeInt, 55 Type: schema.TypeSet,
56 Elem: &schema.Schema{Type: schema.TypeString},
56 Optional: true, 57 Optional: true,
58 Set: schema.HashString,
57 }, 59 },
58 60
59 "check_rate": { 61 "check_rate": {
@@ -223,7 +225,7 @@ func CreateTest(d *schema.ResourceData, meta interface{}) error {
223 TestType: d.Get("test_type").(string), 225 TestType: d.Get("test_type").(string),
224 Paused: d.Get("paused").(bool), 226 Paused: d.Get("paused").(bool),
225 Timeout: d.Get("timeout").(int), 227 Timeout: d.Get("timeout").(int),
226 ContactID: d.Get("contact_id").(int), 228 ContactGroup: castSetToSliceStrings(d.Get("contact_group").(*schema.Set).List()),
227 Confirmation: d.Get("confirmations").(int), 229 Confirmation: d.Get("confirmations").(int),
228 Port: d.Get("port").(int), 230 Port: d.Get("port").(int),
229 TriggerRate: d.Get("trigger_rate").(int), 231 TriggerRate: d.Get("trigger_rate").(int),
@@ -312,7 +314,7 @@ func ReadTest(d *schema.ResourceData, meta interface{}) error {
312 d.Set("test_type", testResp.TestType) 314 d.Set("test_type", testResp.TestType)
313 d.Set("paused", testResp.Paused) 315 d.Set("paused", testResp.Paused)
314 d.Set("timeout", testResp.Timeout) 316 d.Set("timeout", testResp.Timeout)
315 d.Set("contact_id", testResp.ContactID) 317 d.Set("contact_group", testResp.ContactGroup)
316 d.Set("confirmations", testResp.Confirmation) 318 d.Set("confirmations", testResp.Confirmation)
317 d.Set("port", testResp.Port) 319 d.Set("port", testResp.Port)
318 d.Set("trigger_rate", testResp.TriggerRate) 320 d.Set("trigger_rate", testResp.TriggerRate)
@@ -356,8 +358,8 @@ func getStatusCakeTestInput(d *schema.ResourceData) *statuscake.Test {
356 if v, ok := d.GetOk("check_rate"); ok { 358 if v, ok := d.GetOk("check_rate"); ok {
357 test.CheckRate = v.(int) 359 test.CheckRate = v.(int)
358 } 360 }
359 if v, ok := d.GetOk("contact_id"); ok { 361 if v, ok := d.GetOk("contact_group"); ok {
360 test.ContactID = v.(int) 362 test.ContactGroup = castSetToSliceStrings(v.(*schema.Set).List())
361 } 363 }
362 if v, ok := d.GetOk("test_type"); ok { 364 if v, ok := d.GetOk("test_type"); ok {
363 test.TestType = v.(string) 365 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) {
72 resource.TestCheckResourceAttr("statuscake_test.google", "check_rate", "500"), 72 resource.TestCheckResourceAttr("statuscake_test.google", "check_rate", "500"),
73 resource.TestCheckResourceAttr("statuscake_test.google", "paused", "true"), 73 resource.TestCheckResourceAttr("statuscake_test.google", "paused", "true"),
74 resource.TestCheckResourceAttr("statuscake_test.google", "timeout", "40"), 74 resource.TestCheckResourceAttr("statuscake_test.google", "timeout", "40"),
75 resource.TestCheckResourceAttr("statuscake_test.google", "contact_id", "0"),
76 resource.TestCheckResourceAttr("statuscake_test.google", "confirmations", "0"), 75 resource.TestCheckResourceAttr("statuscake_test.google", "confirmations", "0"),
77 resource.TestCheckResourceAttr("statuscake_test.google", "trigger_rate", "20"), 76 resource.TestCheckResourceAttr("statuscake_test.google", "trigger_rate", "20"),
78 resource.TestCheckResourceAttr("statuscake_test.google", "custom_header", "{ \"Content-Type\": \"application/x-www-form-urlencoded\" }"), 77 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
159 err = check(key, value, strconv.FormatBool(test.Paused)) 158 err = check(key, value, strconv.FormatBool(test.Paused))
160 case "timeout": 159 case "timeout":
161 err = check(key, value, strconv.Itoa(test.Timeout)) 160 err = check(key, value, strconv.Itoa(test.Timeout))
162 case "contact_id": 161 case "contact_group":
163 err = check(key, value, strconv.Itoa(test.ContactID)) 162 for _, tv := range test.ContactGroup {
163 err = check(key, value, tv)
164 if err != nil {
165 return err
166 }
167 }
164 case "confirmations": 168 case "confirmations":
165 err = check(key, value, strconv.Itoa(test.Confirmation)) 169 err = check(key, value, strconv.Itoa(test.Confirmation))
166 case "trigger_rate": 170 case "trigger_rate":
@@ -214,13 +218,10 @@ func testAccTestCheckDestroy(test *statuscake.Test) resource.TestCheckFunc {
214} 218}
215 219
216func interpolateTerraformTemplate(template string) string { 220func interpolateTerraformTemplate(template string) string {
217 testContactGroupId := 43402 221 testContactGroupId := "43402"
218 222
219 if v := os.Getenv("STATUSCAKE_TEST_CONTACT_GROUP_ID"); v != "" { 223 if v := os.Getenv("STATUSCAKE_TEST_CONTACT_GROUP_ID"); v != "" {
220 id, err := strconv.Atoi(v) 224 testContactGroupId = v
221 if err == nil {
222 testContactGroupId = id
223 }
224 } 225 }
225 226
226 return fmt.Sprintf(template, testContactGroupId) 227 return fmt.Sprintf(template, testContactGroupId)
@@ -233,7 +234,7 @@ resource "statuscake_test" "google" {
233 test_type = "HTTP" 234 test_type = "HTTP"
234 check_rate = 300 235 check_rate = 300
235 timeout = 10 236 timeout = 10
236 contact_id = %d 237 contact_group = ["%s"]
237 confirmations = 1 238 confirmations = 1
238 trigger_rate = 10 239 trigger_rate = 10
239} 240}
@@ -277,7 +278,7 @@ resource "statuscake_test" "google" {
277 test_type = "TCP" 278 test_type = "TCP"
278 check_rate = 300 279 check_rate = 300
279 timeout = 10 280 timeout = 10
280 contact_id = %d 281 contact_group = ["%s"]
281 confirmations = 1 282 confirmations = 1
282 port = 80 283 port = 80
283} 284}
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.
14 14
15```hcl 15```hcl
16resource "statuscake_test" "google" { 16resource "statuscake_test" "google" {
17 website_name = "google.com" 17 website_name = "google.com"
18 website_url = "www.google.com" 18 website_url = "www.google.com"
19 test_type = "HTTP" 19 test_type = "HTTP"
20 check_rate = 300 20 check_rate = 300
21 contact_id = 12345 21 contact_group = ["12345"]
22} 22}
23``` 23```
24 24
@@ -29,7 +29,7 @@ The following arguments are supported:
29* `website_name` - (Required) This is the name of the test and the website to be monitored. 29* `website_name` - (Required) This is the name of the test and the website to be monitored.
30* `website_url` - (Required) The URL of the website to be monitored 30* `website_url` - (Required) The URL of the website to be monitored
31* `check_rate` - (Optional) Test check rate in seconds. Defaults to 300 31* `check_rate` - (Optional) Test check rate in seconds. Defaults to 300
32* `contact_id` - (Optional) The id of the contact group to be add to the test. Each test can have only one. 32* `contact_group` - (Optional) Set test contact groups, must be array of strings.
33* `test_type` - (Required) The type of Test. Either HTTP, TCP, PING, or DNS 33* `test_type` - (Required) The type of Test. Either HTTP, TCP, PING, or DNS
34* `paused` - (Optional) Whether or not the test is paused. Defaults to false. 34* `paused` - (Optional) Whether or not the test is paused. Defaults to false.
35* `timeout` - (Optional) The timeout of the test in seconds. 35* `timeout` - (Optional) The timeout of the test in seconds.