]> git.immae.eu Git - github/fretlink/terraform-provider-statuscake.git/blobdiff - statuscake/resource_statuscaketest.go
fix reading of test
[github/fretlink/terraform-provider-statuscake.git] / statuscake / resource_statuscaketest.go
index b0dc84f2b5b2ae3ea8486483677cc96de19db69e..88c7363dbd88025db9f679f388ceb58206cdd2e2 100644 (file)
@@ -34,6 +34,9 @@ func resourceStatusCakeTest() *schema.Resource {
                Update: UpdateTest,
                Delete: DeleteTest,
                Read:   ReadTest,
+               Importer: &schema.ResourceImporter{
+                       State: schema.ImportStatePassthrough,
+               },
 
                Schema: map[string]*schema.Schema{
                        "test_id": {
@@ -52,10 +55,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": {
@@ -207,6 +218,12 @@ func resourceStatusCakeTest() *schema.Resource {
                                Optional: true,
                        },
 
+                       "enable_ssl_alert": {
+                               Type:     schema.TypeBool,
+                               Optional: true,
+                               Default:  false,
+                       },
+
                        "follow_redirect": {
                                Type:     schema.TypeBool,
                                Optional: true,
@@ -225,7 +242,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),
@@ -250,9 +266,16 @@ func CreateTest(d *schema.ResourceData, meta interface{}) error {
                UseJar:         d.Get("use_jar").(int),
                PostRaw:        d.Get("post_raw").(string),
                FinalEndpoint:  d.Get("final_endpoint").(string),
+               EnableSSLAlert: d.Get("enable_ssl_alert").(bool),
                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 +331,15 @@ 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)
        }
+
+       d.Set("contact_id", testResp.ContactID)
+       d.Set("contact_group", testResp.ContactGroup)
        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)
@@ -334,9 +359,19 @@ func ReadTest(d *schema.ResourceData, meta interface{}) error {
        d.Set("do_not_find", testResp.DoNotFind)
        d.Set("status_codes", testResp.StatusCodes)
        d.Set("use_jar", testResp.UseJar)
+       d.Set("user_agent", testResp.UserAgent)
        d.Set("post_raw", testResp.PostRaw)
        d.Set("final_endpoint", testResp.FinalEndpoint)
+       d.Set("enable_ssl_alert", testResp.EnableSSLAlert)
        d.Set("follow_redirect", testResp.FollowRedirect)
+       d.Set("ping_url", testResp.PingURL)
+       d.Set("basic_user", testResp.BasicUser)
+       d.Set("basic_pass", testResp.BasicPass)
+       d.Set("public", testResp.Public)
+       d.Set("branding", testResp.Branding)
+       d.Set("virus", testResp.Virus)
+       d.Set("real_browser", testResp.RealBrowser)
+       d.Set("RealBrowser", testResp.TestTags)
 
        return nil
 }
@@ -360,6 +395,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)
@@ -436,6 +473,9 @@ func getStatusCakeTestInput(d *schema.ResourceData) *statuscake.Test {
        if v, ok := d.GetOk("final_endpoint"); ok {
                test.FinalEndpoint = v.(string)
        }
+       if v, ok := d.GetOk("enable_ssl_alert"); ok {
+               test.EnableSSLAlert = v.(bool)
+       }
        if v, ok := d.GetOk("follow_redirect"); ok {
                test.FollowRedirect = v.(bool)
        }