diff options
author | Juan Carlos Alonso <me@jcalonso.com> | 2019-06-10 12:19:15 +0100 |
---|---|---|
committer | Juan Carlos Alonso <me@jcalonso.com> | 2019-06-10 12:19:15 +0100 |
commit | 70c40d15e5f05789f68ccee392f7316a0ae0ac38 (patch) | |
tree | 2b2e0e18a9783c1f05eda9262fdfa929c4fea760 /statuscake/resource_statuscaketest.go | |
parent | 844b5a68d8af4791755b8f0ad293cc99f5959183 (diff) | |
download | terraform-provider-statuscake-70c40d15e5f05789f68ccee392f7316a0ae0ac38.tar.gz terraform-provider-statuscake-70c40d15e5f05789f68ccee392f7316a0ae0ac38.tar.zst terraform-provider-statuscake-70c40d15e5f05789f68ccee392f7316a0ae0ac38.zip |
Add support for contact_id and mark it as deprecated
This makes the contact_group change backwards compatible
Diffstat (limited to 'statuscake/resource_statuscaketest.go')
-rw-r--r-- | statuscake/resource_statuscaketest.go | 32 |
1 files changed, 26 insertions, 6 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) |