]> git.immae.eu Git - github/fretlink/terraform-provider-statuscake.git/commitdiff
Merge pull request #34 from jcalonso/fix/contact-group-backwards-compatible
authorMat Schaffer <mat@schaffer.me>
Thu, 13 Jun 2019 05:59:37 +0000 (14:59 +0900)
committerGitHub <noreply@github.com>
Thu, 13 Jun 2019 05:59:37 +0000 (14:59 +0900)
Add support back for contact_id and mark it as deprecated

CHANGELOG.md
statuscake/resource_statuscaketest.go
statuscake/resource_statuscaketest_test.go
website/docs/r/test.html.markdown

index 117c54ed8d432e93111d9dbbc96e95536521ded2..eea86891b8d370a1660c28795357fc71dceae656 100644 (file)
@@ -2,7 +2,7 @@
 
 NOTES:
 
-* resource/statuscake_test: `contact_id (int)` has been replaced with `contact_group (type: list)`
+* resource/statuscake_test: `contact_id (int)` has been deprecated, use instead: `contact_group (type: list)`
 * resource:statuscake_test: `test_tags` has been changed from a CSV string to list of strings
 
 
index b0dc84f2b5b2ae3ea8486483677cc96de19db69e..b062456ae5140b72ec588a6c42c4a67a1e39ef5c 100644 (file)
@@ -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)
index 0ea1e2b5553c80e79ade3f7c00124f02d89ed72d..bd609d84038a681dd7235b0d01c516189f843438 100644 (file)
@@ -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"
index 9c1fb35819e1bf20cd01dfeeeb46e8050de03d08..6c65f1004ab76110671e3c1f20fe68e1af3c7782 100644 (file)
@@ -29,6 +29,7 @@ The following arguments are supported:
 * `website_name` - (Required) This is the name of the test and the website to be monitored.
 * `website_url` - (Required) The URL of the website to be monitored
 * `check_rate` - (Optional) Test check rate in seconds. Defaults to 300
+* `contact_id` - **Deprecated** (Optional) The id of the contact group to be added to the test. Each test can have only one. 
 * `contact_group` - (Optional) Set test contact groups, must be array of strings. 
 * `test_type` - (Required) The type of Test. Either HTTP, TCP, PING, or DNS
 * `paused` - (Optional) Whether or not the test is paused. Defaults to false.
@@ -51,7 +52,7 @@ The following arguments are supported:
 * `do_not_find` - (Optional) If the above string should be found to trigger a alert. 1 = will trigger if find_string found.
 * `real_browser` - (Optional) Use 1 to TURN OFF real browser testing.
 * `test_tags` - (Optional) Set test tags, must be array of strings.
-* `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".
+* `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".
 * `use_jar` - (Optional) Set to true to enable the Cookie Jar. Required for some redirects. Default is false.
 * `post_raw` - (Optional) Use to populate the RAW POST data field on the test.
 * `final_endpoint` - (Optional) Use to specify the expected Final URL in the testing process.