diff options
Diffstat (limited to 'statuscake')
-rw-r--r-- | statuscake/resource_statuscaketest.go | 32 | ||||
-rw-r--r-- | statuscake/resource_statuscaketest_test.go | 32 |
2 files changed, 57 insertions, 7 deletions
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 | ||
33 | func 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 | |||
33 | func TestAccStatusCake_tcp(t *testing.T) { | 52 | func 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 | 261 | const testAccTestConfig_deprecated = ` | |
262 | resource "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 | ` | ||
243 | const testAccTestConfig_update = ` | 273 | const testAccTestConfig_update = ` |
244 | resource "statuscake_test" "google" { | 274 | resource "statuscake_test" "google" { |
245 | website_name = "google.com" | 275 | website_name = "google.com" |