aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMat Schaffer <mat@schaffer.me>2019-06-13 14:59:37 +0900
committerGitHub <noreply@github.com>2019-06-13 14:59:37 +0900
commitccbb72b7349103fd7e39a47a2ec5312bcc00017f (patch)
tree624507dffe7152bd846495fcd08be7f7cee4dab2
parent3cd2d4f34aefe6090b287b2b4c26049819414e46 (diff)
parent23a4886b56d32dce724d4e6cac2cd0be4fca7743 (diff)
downloadterraform-provider-statuscake-ccbb72b7349103fd7e39a47a2ec5312bcc00017f.tar.gz
terraform-provider-statuscake-ccbb72b7349103fd7e39a47a2ec5312bcc00017f.tar.zst
terraform-provider-statuscake-ccbb72b7349103fd7e39a47a2ec5312bcc00017f.zip
Merge pull request #34 from jcalonso/fix/contact-group-backwards-compatible
Add support back for contact_id and mark it as deprecated
-rw-r--r--CHANGELOG.md2
-rw-r--r--statuscake/resource_statuscaketest.go32
-rw-r--r--statuscake/resource_statuscaketest_test.go32
-rw-r--r--website/docs/r/test.html.markdown3
4 files changed, 60 insertions, 9 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 117c54e..eea8689 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,7 +2,7 @@
2 2
3NOTES: 3NOTES:
4 4
5* resource/statuscake_test: `contact_id (int)` has been replaced with `contact_group (type: list)` 5* resource/statuscake_test: `contact_id (int)` has been deprecated, use instead: `contact_group (type: list)`
6* resource:statuscake_test: `test_tags` has been changed from a CSV string to list of strings 6* resource:statuscake_test: `test_tags` has been changed from a CSV string to list of strings
7 7
8 8
diff --git a/statuscake/resource_statuscaketest.go b/statuscake/resource_statuscaketest.go
index b0dc84f..b062456 100644
--- a/statuscake/resource_statuscaketest.go
+++ b/statuscake/resource_statuscaketest.go
@@ -52,10 +52,18 @@ func resourceStatusCakeTest() *schema.Resource {
52 }, 52 },
53 53
54 "contact_group": { 54 "contact_group": {
55 Type: schema.TypeSet, 55 Type: schema.TypeSet,
56 Elem: &schema.Schema{Type: schema.TypeString}, 56 Elem: &schema.Schema{Type: schema.TypeString},
57 Optional: true, 57 Optional: true,
58 Set: schema.HashString, 58 Set: schema.HashString,
59 ConflictsWith: []string{"contact_id"},
60 },
61
62 "contact_id": {
63 Type: schema.TypeInt,
64 Optional: true,
65 ConflictsWith: []string{"contact_group"},
66 Deprecated: "use contact_group instead",
59 }, 67 },
60 68
61 "check_rate": { 69 "check_rate": {
@@ -225,7 +233,6 @@ func CreateTest(d *schema.ResourceData, meta interface{}) error {
225 TestType: d.Get("test_type").(string), 233 TestType: d.Get("test_type").(string),
226 Paused: d.Get("paused").(bool), 234 Paused: d.Get("paused").(bool),
227 Timeout: d.Get("timeout").(int), 235 Timeout: d.Get("timeout").(int),
228 ContactGroup: castSetToSliceStrings(d.Get("contact_group").(*schema.Set).List()),
229 Confirmation: d.Get("confirmations").(int), 236 Confirmation: d.Get("confirmations").(int),
230 Port: d.Get("port").(int), 237 Port: d.Get("port").(int),
231 TriggerRate: d.Get("trigger_rate").(int), 238 TriggerRate: d.Get("trigger_rate").(int),
@@ -253,6 +260,12 @@ func CreateTest(d *schema.ResourceData, meta interface{}) error {
253 FollowRedirect: d.Get("follow_redirect").(bool), 260 FollowRedirect: d.Get("follow_redirect").(bool),
254 } 261 }
255 262
263 if v, ok := d.GetOk("contact_group"); ok {
264 newTest.ContactGroup = castSetToSliceStrings(v.(*schema.Set).List())
265 } else if v, ok := d.GetOk("contact_id"); ok {
266 newTest.ContactID = v.(int)
267 }
268
256 log.Printf("[DEBUG] Creating new StatusCake Test: %s", d.Get("website_name").(string)) 269 log.Printf("[DEBUG] Creating new StatusCake Test: %s", d.Get("website_name").(string))
257 270
258 response, err := client.Tests().Update(newTest) 271 response, err := client.Tests().Update(newTest)
@@ -308,13 +321,18 @@ func ReadTest(d *schema.ResourceData, meta interface{}) error {
308 if err != nil { 321 if err != nil {
309 return fmt.Errorf("Error Getting StatusCake Test Details for %s: Error: %s", d.Id(), err) 322 return fmt.Errorf("Error Getting StatusCake Test Details for %s: Error: %s", d.Id(), err)
310 } 323 }
324
325 if v, ok := d.GetOk("contact_group"); ok {
326 d.Set("contact_group", v)
327 } else if v, ok := d.GetOk("contact_id"); ok {
328 d.Set("contact_id", v)
329 }
311 d.Set("website_name", testResp.WebsiteName) 330 d.Set("website_name", testResp.WebsiteName)
312 d.Set("website_url", testResp.WebsiteURL) 331 d.Set("website_url", testResp.WebsiteURL)
313 d.Set("check_rate", testResp.CheckRate) 332 d.Set("check_rate", testResp.CheckRate)
314 d.Set("test_type", testResp.TestType) 333 d.Set("test_type", testResp.TestType)
315 d.Set("paused", testResp.Paused) 334 d.Set("paused", testResp.Paused)
316 d.Set("timeout", testResp.Timeout) 335 d.Set("timeout", testResp.Timeout)
317 d.Set("contact_group", testResp.ContactGroup)
318 d.Set("confirmations", testResp.Confirmation) 336 d.Set("confirmations", testResp.Confirmation)
319 d.Set("port", testResp.Port) 337 d.Set("port", testResp.Port)
320 d.Set("trigger_rate", testResp.TriggerRate) 338 d.Set("trigger_rate", testResp.TriggerRate)
@@ -360,6 +378,8 @@ func getStatusCakeTestInput(d *schema.ResourceData) *statuscake.Test {
360 } 378 }
361 if v, ok := d.GetOk("contact_group"); ok { 379 if v, ok := d.GetOk("contact_group"); ok {
362 test.ContactGroup = castSetToSliceStrings(v.(*schema.Set).List()) 380 test.ContactGroup = castSetToSliceStrings(v.(*schema.Set).List())
381 } else if v, ok := d.GetOk("contact_id"); ok {
382 test.ContactID = v.(int)
363 } 383 }
364 if v, ok := d.GetOk("test_type"); ok { 384 if v, ok := d.GetOk("test_type"); ok {
365 test.TestType = v.(string) 385 test.TestType = v.(string)
diff --git a/statuscake/resource_statuscaketest_test.go b/statuscake/resource_statuscaketest_test.go
index 0ea1e2b..bd609d8 100644
--- a/statuscake/resource_statuscaketest_test.go
+++ b/statuscake/resource_statuscaketest_test.go
@@ -30,6 +30,25 @@ func TestAccStatusCake_basic(t *testing.T) {
30 }) 30 })
31} 31}
32 32
33func TestAccStatusCake_basic_deprecated_contact_ID(t *testing.T) {
34 var test statuscake.Test
35
36 resource.Test(t, resource.TestCase{
37 PreCheck: func() { testAccPreCheck(t) },
38 Providers: testAccProviders,
39 CheckDestroy: testAccTestCheckDestroy(&test),
40 Steps: []resource.TestStep{
41 {
42 Config: interpolateTerraformTemplate(testAccTestConfig_deprecated),
43 Check: resource.ComposeTestCheckFunc(
44 testAccTestCheckExists("statuscake_test.google", &test),
45 testAccTestCheckAttributes("statuscake_test.google", &test),
46 ),
47 },
48 },
49 })
50}
51
33func TestAccStatusCake_tcp(t *testing.T) { 52func TestAccStatusCake_tcp(t *testing.T) {
34 var test statuscake.Test 53 var test statuscake.Test
35 54
@@ -239,7 +258,18 @@ resource "statuscake_test" "google" {
239 trigger_rate = 10 258 trigger_rate = 10
240} 259}
241` 260`
242 261const testAccTestConfig_deprecated = `
262resource "statuscake_test" "google" {
263 website_name = "google.com"
264 website_url = "www.google.com"
265 test_type = "HTTP"
266 check_rate = 300
267 timeout = 10
268 contact_id = %s
269 confirmations = 1
270 trigger_rate = 10
271}
272`
243const testAccTestConfig_update = ` 273const testAccTestConfig_update = `
244resource "statuscake_test" "google" { 274resource "statuscake_test" "google" {
245 website_name = "google.com" 275 website_name = "google.com"
diff --git a/website/docs/r/test.html.markdown b/website/docs/r/test.html.markdown
index 9c1fb35..6c65f10 100644
--- a/website/docs/r/test.html.markdown
+++ b/website/docs/r/test.html.markdown
@@ -29,6 +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` - **Deprecated** (Optional) The id of the contact group to be added to the test. Each test can have only one.
32* `contact_group` - (Optional) Set test contact groups, must be array of strings. 33* `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 34* `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. 35* `paused` - (Optional) Whether or not the test is paused. Defaults to false.
@@ -51,7 +52,7 @@ The following arguments are supported:
51* `do_not_find` - (Optional) If the above string should be found to trigger a alert. 1 = will trigger if find_string found. 52* `do_not_find` - (Optional) If the above string should be found to trigger a alert. 1 = will trigger if find_string found.
52* `real_browser` - (Optional) Use 1 to TURN OFF real browser testing. 53* `real_browser` - (Optional) Use 1 to TURN OFF real browser testing.
53* `test_tags` - (Optional) Set test tags, must be array of strings. 54* `test_tags` - (Optional) Set test tags, must be array of strings.
54* `status_codes` - (Optional) Comma Seperated List of StatusCodes to Trigger Error on. Defaults are "204, 205, 206, 303, 400, 401, 403, 404, 405, 406, 408, 410, 413, 444, 429, 494, 495, 496, 499, 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, 521, 522, 523, 524, 520, 598, 599". 55* `status_codes` - (Optional) Comma Separated List of StatusCodes to Trigger Error on. Defaults are "204, 205, 206, 303, 400, 401, 403, 404, 405, 406, 408, 410, 413, 444, 429, 494, 495, 496, 499, 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, 521, 522, 523, 524, 520, 598, 599".
55* `use_jar` - (Optional) Set to true to enable the Cookie Jar. Required for some redirects. Default is false. 56* `use_jar` - (Optional) Set to true to enable the Cookie Jar. Required for some redirects. Default is false.
56* `post_raw` - (Optional) Use to populate the RAW POST data field on the test. 57* `post_raw` - (Optional) Use to populate the RAW POST data field on the test.
57* `final_endpoint` - (Optional) Use to specify the expected Final URL in the testing process. 58* `final_endpoint` - (Optional) Use to specify the expected Final URL in the testing process.