From ed5e20e8578d3a01b41fecf3f075887bd3e24584 Mon Sep 17 00:00:00 2001 From: Mat Schaffer Date: Thu, 1 Feb 2018 16:08:10 +0900 Subject: Mark basic_pass sensitive Avoids showing the password in plan output --- statuscake/resource_statuscaketest.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'statuscake/resource_statuscaketest.go') diff --git a/statuscake/resource_statuscaketest.go b/statuscake/resource_statuscaketest.go index 459c71a..e824955 100644 --- a/statuscake/resource_statuscaketest.go +++ b/statuscake/resource_statuscaketest.go @@ -123,8 +123,9 @@ func resourceStatusCakeTest() *schema.Resource { }, "basic_pass": { - Type: schema.TypeString, - Optional: true, + Type: schema.TypeString, + Optional: true, + Sensitive: true, }, "public": { -- cgit v1.2.3 From 5c7efdcb8c0a6d3d21f1fb1481bb95e402296d77 Mon Sep 17 00:00:00 2001 From: Mat Schaffer Date: Thu, 1 Feb 2018 16:10:15 +0900 Subject: Remove status codes default In my testing, the default response was `[""]` and having the default provided cause test assertion failures --- statuscake/resource_statuscaketest.go | 4 ---- 1 file changed, 4 deletions(-) (limited to 'statuscake/resource_statuscaketest.go') diff --git a/statuscake/resource_statuscaketest.go b/statuscake/resource_statuscaketest.go index e824955..8e67bcd 100644 --- a/statuscake/resource_statuscaketest.go +++ b/statuscake/resource_statuscaketest.go @@ -176,10 +176,6 @@ func resourceStatusCakeTest() *schema.Resource { "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": { -- cgit v1.2.3 From 89027b6ac2e02ed5097e2aed6e2a5e0b0476d5f9 Mon Sep 17 00:00:00 2001 From: Mat Schaffer Date: Thu, 1 Feb 2018 16:14:33 +0900 Subject: Switch node locations to a set and consider empty string to be empty set Note that we also don't check the individual locations anymore. The key numbers will be randomized and not testing content seems to be the method employed by the AWS provider as well https://github.com/terraform-providers/terraform-provider-aws/blob/81bba6b1f567aed561c6a6a30916504ee0886c68/aws/resource_aws_autoscaling_group_test.go#L404 --- statuscake/resource_statuscaketest.go | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'statuscake/resource_statuscaketest.go') diff --git a/statuscake/resource_statuscaketest.go b/statuscake/resource_statuscaketest.go index 8e67bcd..b2b0c68 100644 --- a/statuscake/resource_statuscaketest.go +++ b/statuscake/resource_statuscaketest.go @@ -10,16 +10,24 @@ import ( "github.com/hashicorp/terraform/helper/schema" ) -func castInterfaceToSliceStrings(in interface{}) []string { - input := in.([]interface{}) - res := make([]string, len(input)) +func castSetToSliceStrings(configured []interface{}) []string { + res := make([]string, len(configured)) - for i, element := range input { + for i, element := range configured { res[i] = element.(string) } return res } +// Special handling for node_locations since statuscake will return `[""]` for the empty case +func considerEmptyStringAsEmptyArray(in []string) []string { + if len(in) == 1 && in[0] == "" { + return []string{} + } else { + return in + } +} + func resourceStatusCakeTest() *schema.Resource { return &schema.Resource{ Create: CreateTest, @@ -107,9 +115,10 @@ func resourceStatusCakeTest() *schema.Resource { }, "node_locations": { - Type: schema.TypeList, + Type: schema.TypeSet, Elem: &schema.Schema{Type: schema.TypeString}, Optional: true, + Set: schema.HashString, }, "ping_url": { @@ -219,7 +228,7 @@ func CreateTest(d *schema.ResourceData, meta interface{}) error { UserAgent: d.Get("user_agent").(string), Status: d.Get("status").(string), Uptime: d.Get("uptime").(float64), - NodeLocations: castInterfaceToSliceStrings(d.Get("node_locations")), + NodeLocations: castSetToSliceStrings(d.Get("node_locations").(*schema.Set).List()), PingURL: d.Get("ping_url").(string), BasicUser: d.Get("basic_user").(string), BasicPass: d.Get("basic_pass").(string), @@ -308,7 +317,7 @@ func ReadTest(d *schema.ResourceData, meta interface{}) error { d.Set("user_agent", testResp.UserAgent) d.Set("status", testResp.Status) d.Set("uptime", testResp.Uptime) - if err := d.Set("node_locations", testResp.NodeLocations); err != nil { + if err := d.Set("node_locations", considerEmptyStringAsEmptyArray(testResp.NodeLocations)); err != nil { return fmt.Errorf("[WARN] Error setting node locations: %s", err) } d.Set("ping_url", testResp.PingURL) @@ -377,7 +386,7 @@ func getStatusCakeTestInput(d *schema.ResourceData) *statuscake.Test { test.UserAgent = v.(string) } if v, ok := d.GetOk("node_locations"); ok { - test.NodeLocations = castInterfaceToSliceStrings(v) + test.NodeLocations = castSetToSliceStrings(v.(*schema.Set).List()) } if v, ok := d.GetOk("ping_url"); ok { test.PingURL = v.(string) -- cgit v1.2.3 From ef20d8d74891bfcfbf17088c4cd9c39cd1e347dd Mon Sep 17 00:00:00 2001 From: Mat Schaffer Date: Thu, 1 Feb 2018 16:15:21 +0900 Subject: Don't attempt to set or verify values which aren't present in the details response The `TestCheckResourceAttr` tests can stay since they rely on the state from the previous apply. --- statuscake/resource_statuscaketest.go | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'statuscake/resource_statuscaketest.go') diff --git a/statuscake/resource_statuscaketest.go b/statuscake/resource_statuscaketest.go index b2b0c68..d7d3f36 100644 --- a/statuscake/resource_statuscaketest.go +++ b/statuscake/resource_statuscaketest.go @@ -314,24 +314,19 @@ func ReadTest(d *schema.ResourceData, meta interface{}) error { 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) if err := d.Set("node_locations", considerEmptyStringAsEmptyArray(testResp.NodeLocations)); err != nil { return fmt.Errorf("[WARN] Error setting node locations: %s", err) } - 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) + // Even after WebsiteHost is set, the API returns "" + // API docs aren't clear on usage will only override state if we get a non-empty value back + if testResp.WebsiteHost != "" { + d.Set("website_host", testResp.WebsiteHost) + } 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) -- cgit v1.2.3