From 754f142077413d1cfd1e3c8e2fc3f3c0c341ca69 Mon Sep 17 00:00:00 2001 From: Andrew N Golovkov Date: Tue, 16 Jan 2018 15:07:28 +0200 Subject: update statuscake provider for support all the features from the statuscake module --- statuscake/resource_statuscaketest.go | 258 ++++++++++++++++++++++++++--- statuscake/resource_statuscaketest_test.go | 103 +++++++++++- 2 files changed, 335 insertions(+), 26 deletions(-) (limited to 'statuscake') diff --git a/statuscake/resource_statuscaketest.go b/statuscake/resource_statuscaketest.go index 101ee83..27cf9bf 100644 --- a/statuscake/resource_statuscaketest.go +++ b/statuscake/resource_statuscaketest.go @@ -34,7 +34,7 @@ func resourceStatusCakeTest() *schema.Resource { }, "contact_id": { - Type: schema.TypeInt, + Type: schema.TypeString, Optional: true, }, @@ -76,6 +76,120 @@ func resourceStatusCakeTest() *schema.Resource { Optional: true, Default: 5, }, + "custom_header": { + Type: schema.TypeString, + Optional: true, + }, + + "user_agent": { + Type: schema.TypeString, + Optional: true, + }, + + "status": { + Type: schema.TypeString, + Optional: true, + }, + + "uptime": { + Type: schema.TypeFloat, + Optional: true, + }, + + "node_locations": { + Type: schema.TypeList, + Elem: &schema.Schema{Type: schema.TypeString}, + Optional: true, + }, + + "ping_url": { + Type: schema.TypeString, + Optional: true, + }, + + "basic_user": { + Type: schema.TypeString, + Optional: true, + }, + + "basic_pass": { + Type: schema.TypeString, + Optional: true, + }, + + "public": { + Type: schema.TypeInt, + Optional: true, + }, + + "logo_image": { + Type: schema.TypeString, + Optional: true, + }, + + "branding": { + Type: schema.TypeInt, + Optional: true, + }, + + "website_host": { + Type: schema.TypeString, + Optional: true, + }, + + "virus": { + Type: schema.TypeInt, + Optional: true, + }, + + "find_string": { + Type: schema.TypeString, + Optional: true, + }, + + "do_not_find": { + Type: schema.TypeBool, + Optional: true, + }, + + "real_browser": { + Type: schema.TypeInt, + Optional: true, + }, + + "test_tags": { + Type: schema.TypeString, + Optional: true, + }, + + "status_codes": { + Type: schema.TypeString, + Optional: true, + Default: "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": { + Type: schema.TypeInt, + Optional: true, + }, + + "post_raw": { + Type: schema.TypeString, + Optional: true, + }, + + "final_endpoint": { + Type: schema.TypeString, + Optional: true, + }, + + "follow_redirect": { + Type: schema.TypeBool, + Optional: true, + }, }, } } @@ -84,16 +198,38 @@ func CreateTest(d *schema.ResourceData, meta interface{}) error { client := meta.(*statuscake.Client) newTest := &statuscake.Test{ - WebsiteName: d.Get("website_name").(string), - WebsiteURL: d.Get("website_url").(string), - CheckRate: d.Get("check_rate").(int), - TestType: d.Get("test_type").(string), - Paused: d.Get("paused").(bool), - Timeout: d.Get("timeout").(int), - ContactID: d.Get("contact_id").(int), - Confirmation: d.Get("confirmations").(int), - Port: d.Get("port").(int), - TriggerRate: d.Get("trigger_rate").(int), + WebsiteName: d.Get("website_name").(string), + WebsiteURL: d.Get("website_url").(string), + CheckRate: d.Get("check_rate").(int), + TestType: d.Get("test_type").(string), + Paused: d.Get("paused").(bool), + Timeout: d.Get("timeout").(int), + ContactID: d.Get("contact_id").(string), + Confirmation: d.Get("confirmations").(int), + Port: d.Get("port").(int), + TriggerRate: d.Get("trigger_rate").(int), + CustomHeader: d.Get("custom_header").(string), + UserAgent: d.Get("user_agent").(string), + Status: d.Get("status").(string), + Uptime: d.Get("uptime").(float64), + NodeLocations: d.Get("node_locations").([]string), + PingURL: d.Get("ping_url").(string), + BasicUser: d.Get("basic_user").(string), + BasicPass: d.Get("basic_pass").(string), + Public: d.Get("public").(int), + LogoImage: d.Get("logo_image").(string), + Branding: d.Get("branding").(int), + WebsiteHost: d.Get("website_host").(string), + Virus: d.Get("virus").(int), + FindString: d.Get("find_string").(string), + DoNotFind: d.Get("do_not_find").(bool), + RealBrowser: d.Get("real_browser").(int), + TestTags: d.Get("test_tags").(string), + StatusCodes: d.Get("status_codes").(string), + UseJar: d.Get("use_jar").(int), + PostRaw: d.Get("post_raw").(string), + FinalEndpoint: d.Get("final_endpoint").(string), + FollowRedirect: d.Get("follow_redirect").(bool), } log.Printf("[DEBUG] Creating new StatusCake Test: %s", d.Get("website_name").(string)) @@ -159,6 +295,28 @@ func ReadTest(d *schema.ResourceData, meta interface{}) error { d.Set("confirmations", testResp.Confirmation) d.Set("port", testResp.Port) d.Set("trigger_rate", testResp.TriggerRate) + d.Set("custom_header", testResp.CustomHeader) + d.Set("user_agent", testResp.UserAgent) + d.Set("status", testResp.Status) + d.Set("uptime", testResp.Uptime) + d.Set("node_locations", testResp.NodeLocations) + 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("logo_image", testResp.LogoImage) + d.Set("branding", testResp.Branding) + d.Set("website_host", testResp.WebsiteHost) + d.Set("virus", testResp.Virus) + d.Set("find_string", testResp.FindString) + d.Set("do_not_find", testResp.DoNotFind) + d.Set("real_browser", testResp.RealBrowser) + d.Set("test_tags", testResp.TestTags) + d.Set("status_codes", testResp.StatusCodes) + d.Set("use_jar", testResp.UseJar) + d.Set("post_raw", testResp.PostRaw) + d.Set("final_endpoint", testResp.FinalEndpoint) + d.Set("follow_redirect", testResp.FollowRedirect) return nil } @@ -181,7 +339,7 @@ func getStatusCakeTestInput(d *schema.ResourceData) *statuscake.Test { test.CheckRate = v.(int) } if v, ok := d.GetOk("contact_id"); ok { - test.ContactID = v.(int) + test.ContactID = v.(string) } if v, ok := d.GetOk("test_type"); ok { test.TestType = v.(string) @@ -192,9 +350,6 @@ func getStatusCakeTestInput(d *schema.ResourceData) *statuscake.Test { if v, ok := d.GetOk("timeout"); ok { test.Timeout = v.(int) } - if v, ok := d.GetOk("contact_id"); ok { - test.ContactID = v.(int) - } if v, ok := d.GetOk("confirmations"); ok { test.Confirmation = v.(int) } @@ -204,13 +359,72 @@ func getStatusCakeTestInput(d *schema.ResourceData) *statuscake.Test { if v, ok := d.GetOk("trigger_rate"); ok { test.TriggerRate = v.(int) } - - defaultStatusCodes := "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" - - test.StatusCodes = defaultStatusCodes + if v, ok := d.GetOk("custom_header"); ok { + test.CustomHeader = v.(string) + } + if v, ok := d.GetOk("user_agent"); ok { + test.UserAgent = v.(string) + } + if v, ok := d.GetOk("status"); ok { + test.Status = v.(string) + } + if v, ok := d.GetOk("uptime"); ok { + test.Uptime = v.(float64) + } + if v, ok := d.GetOk("node_locations"); ok { + test.NodeLocations = v.([]string) + } + if v, ok := d.GetOk("ping_url"); ok { + test.PingURL = v.(string) + } + if v, ok := d.GetOk("basic_user"); ok { + test.BasicUser = v.(string) + } + if v, ok := d.GetOk("basic_pass"); ok { + test.BasicPass = v.(string) + } + if v, ok := d.GetOk("public"); ok { + test.Public = v.(int) + } + if v, ok := d.GetOk("logo_image"); ok { + test.LogoImage = v.(string) + } + if v, ok := d.GetOk("branding"); ok { + test.Branding = v.(int) + } + if v, ok := d.GetOk("website_host"); ok { + test.WebsiteHost = v.(string) + } + if v, ok := d.GetOk("virus"); ok { + test.Virus = v.(int) + } + if v, ok := d.GetOk("find_string"); ok { + test.FindString = v.(string) + } + if v, ok := d.GetOk("do_not_find"); ok { + test.DoNotFind = v.(bool) + } + if v, ok := d.GetOk("real_browser"); ok { + test.RealBrowser = v.(int) + } + if v, ok := d.GetOk("test_tags"); ok { + test.TestTags = v.(string) + } + if v, ok := d.GetOk("status_codes"); ok { + test.StatusCodes = v.(string) + } + if v, ok := d.GetOk("use_jar"); ok { + test.UseJar = v.(int) + } + if v, ok := d.GetOk("post_raw"); ok { + test.PostRaw = v.(string) + } + if v, ok := d.GetOk("final_endpoint"); ok { + test.FinalEndpoint = v.(string) + } + if v, ok := d.GetOk("follow_redirect"); ok { + test.FollowRedirect = v.(bool) + } return test } diff --git a/statuscake/resource_statuscaketest_test.go b/statuscake/resource_statuscaketest_test.go index f07fcc5..b39d23c 100644 --- a/statuscake/resource_statuscaketest_test.go +++ b/statuscake/resource_statuscaketest_test.go @@ -74,6 +74,31 @@ func TestAccStatusCake_withUpdate(t *testing.T) { resource.TestCheckResourceAttr("statuscake_test.google", "contact_id", "0"), resource.TestCheckResourceAttr("statuscake_test.google", "confirmations", "0"), resource.TestCheckResourceAttr("statuscake_test.google", "trigger_rate", "20"), + resource.TestCheckResourceAttr("statuscake_test.google", "custom_header", "{ \"Content-Type\": \"application/x-www-form-urlencoded\" }"), + resource.TestCheckResourceAttr("statuscake_test.google", "user_agent", "string9988"), + resource.TestCheckResourceAttr("statuscake_test.google", "status", "string22117"), + resource.TestCheckResourceAttr("statuscake_test.google", "uptime", "3498.27"), + resource.TestCheckResourceAttr("statuscake_test.google", "node_locations.#", "3"), + resource.TestCheckResourceAttr("statuscake_test.google", "node_locations.0", "string16045"), + resource.TestCheckResourceAttr("statuscake_test.google", "node_locations.1", "string19741"), + resource.TestCheckResourceAttr("statuscake_test.google", "node_locations.2", "string12122"), + resource.TestCheckResourceAttr("statuscake_test.google", "ping_url", "string8410"), + resource.TestCheckResourceAttr("statuscake_test.google", "basic_user", "string27052"), + resource.TestCheckResourceAttr("statuscake_test.google", "basic_pass", "string5659"), + resource.TestCheckResourceAttr("statuscake_test.google", "public", "0"), + resource.TestCheckResourceAttr("statuscake_test.google", "logo_image", "string21087"), + resource.TestCheckResourceAttr("statuscake_test.google", "branding", "25875"), + resource.TestCheckResourceAttr("statuscake_test.google", "website_host", "string32368"), + resource.TestCheckResourceAttr("statuscake_test.google", "virus", "1"), + resource.TestCheckResourceAttr("statuscake_test.google", "find_string", "string15212"), + resource.TestCheckResourceAttr("statuscake_test.google", "do_not_find", "false"), + resource.TestCheckResourceAttr("statuscake_test.google", "real_browser", "1"), + resource.TestCheckResourceAttr("statuscake_test.google", "test_tags", "string8191"), + resource.TestCheckResourceAttr("statuscake_test.google", "status_codes", "string23065"), + resource.TestCheckResourceAttr("statuscake_test.google", "use_jar", "1"), + resource.TestCheckResourceAttr("statuscake_test.google", "post_raw", "string32096"), + resource.TestCheckResourceAttr("statuscake_test.google", "final_endpoint", "string10781"), + resource.TestCheckResourceAttr("statuscake_test.google", "follow_redirect", "true"), ), }, }, @@ -137,13 +162,61 @@ func testAccTestCheckAttributes(rn string, test *statuscake.Test) resource.TestC case "timeout": err = check(key, value, strconv.Itoa(test.Timeout)) case "contact_id": - err = check(key, value, strconv.Itoa(test.ContactID)) + err = check(key, value, test.ContactID) case "confirmations": err = check(key, value, strconv.Itoa(test.Confirmation)) case "trigger_rate": err = check(key, value, strconv.Itoa(test.TriggerRate)) + case "custom_header": + err = check(key, value, test.CustomHeader) + case "user_agent": + err = check(key, value, test.UserAgent) + case "status": + err = check(key, value, test.Status) + case "uptime": + err = check(key, value, strconv.FormatFloat(test.Uptime, 'f', -1, 64)) + case "node_locations": + for _, tv := range test.NodeLocations { + err = check(key, value, tv) + if err != nil { + return err + } + } + case "ping_url": + err = check(key, value, test.PingURL) + case "basic_user": + err = check(key, value, test.BasicUser) + case "basic_pass": + err = check(key, value, test.BasicPass) + case "public": + err = check(key, value, strconv.Itoa(test.Public)) + case "logo_image": + err = check(key, value, test.LogoImage) + case "branding": + err = check(key, value, strconv.Itoa(test.Branding)) + case "website_host": + err = check(key, value, test.WebsiteHost) + case "virus": + err = check(key, value, strconv.Itoa(test.Virus)) + case "find_string": + err = check(key, value, test.FindString) + case "do_not_find": + err = check(key, value, strconv.FormatBool(test.DoNotFind)) + case "real_browser": + err = check(key, value, strconv.Itoa(test.RealBrowser)) + case "test_tags": + err = check(key, value, test.TestTags) + case "status_codes": + err = check(key, value, test.StatusCodes) + case "use_jar": + err = check(key, value, strconv.Itoa(test.UseJar)) + case "post_raw": + err = check(key, value, test.PostRaw) + case "final_endpoint": + err = check(key, value, test.FinalEndpoint) + case "follow_redirect": + err = check(key, value, strconv.FormatBool(test.FollowRedirect)) } - if err != nil { return err } @@ -171,7 +244,7 @@ resource "statuscake_test" "google" { test_type = "HTTP" check_rate = 300 timeout = 10 - contact_id = 43402 + contact_id = "43402" confirmations = 1 trigger_rate = 10 } @@ -185,6 +258,28 @@ resource "statuscake_test" "google" { check_rate = 500 paused = true trigger_rate = 20 + custom_header = "{ \"Content-Type\": \"application/x-www-form-urlencoded\" }" + user_agent = "string9988" + status = "string22117" + uptime = 3498.27 + node_locations = [ "string16045", "string19741", "string12122" ] + ping_url = "string8410" + basic_user = "string27052" + basic_pass = "string5659" + public = 0 + logo_image = "string21087" + branding = 25875 + website_host = "string32368" + virus = 1 + find_string = "string15212" + do_not_find = false + real_browser = 1 + test_tags = "string8191" + status_codes = "string23065" + use_jar = 1 + post_raw = "string32096" + final_endpoint = "string10781" + follow_redirect = true } ` @@ -195,7 +290,7 @@ resource "statuscake_test" "google" { test_type = "TCP" check_rate = 300 timeout = 10 - contact_id = 43402 + contact_id = "43402" confirmations = 1 port = 80 } -- cgit v1.2.3