From 70c40d15e5f05789f68ccee392f7316a0ae0ac38 Mon Sep 17 00:00:00 2001 From: Juan Carlos Alonso Date: Mon, 10 Jun 2019 12:19:15 +0100 Subject: Add support for contact_id and mark it as deprecated This makes the contact_group change backwards compatible --- statuscake/resource_statuscaketest.go | 32 ++++++++++++++++++++++++------ statuscake/resource_statuscaketest_test.go | 32 +++++++++++++++++++++++++++++- 2 files changed, 57 insertions(+), 7 deletions(-) (limited to 'statuscake') 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 { }, "contact_group": { - Type: schema.TypeSet, - Elem: &schema.Schema{Type: schema.TypeString}, - Optional: true, - Set: schema.HashString, + Type: schema.TypeSet, + Elem: &schema.Schema{Type: schema.TypeString}, + Optional: true, + Set: schema.HashString, + ConflictsWith: []string{"contact_id"}, + }, + + "contact_id": { + Type: schema.TypeInt, + Optional: true, + ConflictsWith: []string{"contact_group"}, + Deprecated: "use contact_group instead", }, "check_rate": { @@ -225,7 +233,6 @@ func CreateTest(d *schema.ResourceData, meta interface{}) error { TestType: d.Get("test_type").(string), Paused: d.Get("paused").(bool), Timeout: d.Get("timeout").(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), @@ -253,6 +260,12 @@ func CreateTest(d *schema.ResourceData, meta interface{}) error { FollowRedirect: d.Get("follow_redirect").(bool), } + if v, ok := d.GetOk("contact_group"); ok { + newTest.ContactGroup = castSetToSliceStrings(v.(*schema.Set).List()) + } else if v, ok := d.GetOk("contact_id"); ok { + newTest.ContactID = v.(int) + } + log.Printf("[DEBUG] Creating new StatusCake Test: %s", d.Get("website_name").(string)) response, err := client.Tests().Update(newTest) @@ -308,13 +321,18 @@ func ReadTest(d *schema.ResourceData, meta interface{}) error { if err != nil { return fmt.Errorf("Error Getting StatusCake Test Details for %s: Error: %s", d.Id(), err) } + + if v, ok := d.GetOk("contact_group"); ok { + d.Set("contact_group", v) + } else if v, ok := d.GetOk("contact_id"); ok { + d.Set("contact_id", v) + } d.Set("website_name", testResp.WebsiteName) d.Set("website_url", testResp.WebsiteURL) d.Set("check_rate", testResp.CheckRate) d.Set("test_type", testResp.TestType) d.Set("paused", testResp.Paused) d.Set("timeout", testResp.Timeout) - d.Set("contact_group", testResp.ContactGroup) d.Set("confirmations", testResp.Confirmation) d.Set("port", testResp.Port) d.Set("trigger_rate", testResp.TriggerRate) @@ -360,6 +378,8 @@ func getStatusCakeTestInput(d *schema.ResourceData) *statuscake.Test { } if v, ok := d.GetOk("contact_group"); ok { test.ContactGroup = castSetToSliceStrings(v.(*schema.Set).List()) + } else if v, ok := d.GetOk("contact_id"); ok { + test.ContactID = v.(int) } 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 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) { }) } +func TestAccStatusCake_basic_deprecated_contact_ID(t *testing.T) { + var test statuscake.Test + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccTestCheckDestroy(&test), + Steps: []resource.TestStep{ + { + Config: interpolateTerraformTemplate(testAccTestConfig_deprecated), + Check: resource.ComposeTestCheckFunc( + testAccTestCheckExists("statuscake_test.google", &test), + testAccTestCheckAttributes("statuscake_test.google", &test), + ), + }, + }, + }) +} + func TestAccStatusCake_tcp(t *testing.T) { var test statuscake.Test @@ -239,7 +258,18 @@ resource "statuscake_test" "google" { trigger_rate = 10 } ` - +const testAccTestConfig_deprecated = ` +resource "statuscake_test" "google" { + website_name = "google.com" + website_url = "www.google.com" + test_type = "HTTP" + check_rate = 300 + timeout = 10 + contact_id = %s + confirmations = 1 + trigger_rate = 10 +} +` const testAccTestConfig_update = ` resource "statuscake_test" "google" { website_name = "google.com" -- cgit v1.2.3