aboutsummaryrefslogtreecommitdiffhomepage
path: root/statuscake/resource_statuscaketest.go
diff options
context:
space:
mode:
authorAndrew N Golovkov <andrew@callstats.io>2018-02-01 13:24:08 +0200
committerGitHub <noreply@github.com>2018-02-01 13:24:08 +0200
commit538b3c9e581bbf5427209787be0b2c26977e1573 (patch)
tree4f30d86767b126d5f8ee67fa417382e4f0d7fa1d /statuscake/resource_statuscaketest.go
parentc9458806c73b69e6af47eddd83391197b6d2a641 (diff)
parentef20d8d74891bfcfbf17088c4cd9c39cd1e347dd (diff)
downloadterraform-provider-statuscake-538b3c9e581bbf5427209787be0b2c26977e1573.tar.gz
terraform-provider-statuscake-538b3c9e581bbf5427209787be0b2c26977e1573.tar.zst
terraform-provider-statuscake-538b3c9e581bbf5427209787be0b2c26977e1573.zip
Merge pull request #1 from matschaffer/callstats-io-fixes
Updates to avoid perpetual node location diff
Diffstat (limited to 'statuscake/resource_statuscaketest.go')
-rw-r--r--statuscake/resource_statuscaketest.go49
1 files changed, 25 insertions, 24 deletions
diff --git a/statuscake/resource_statuscaketest.go b/statuscake/resource_statuscaketest.go
index 459c71a..d7d3f36 100644
--- a/statuscake/resource_statuscaketest.go
+++ b/statuscake/resource_statuscaketest.go
@@ -10,16 +10,24 @@ import (
10 "github.com/hashicorp/terraform/helper/schema" 10 "github.com/hashicorp/terraform/helper/schema"
11) 11)
12 12
13func castInterfaceToSliceStrings(in interface{}) []string { 13func castSetToSliceStrings(configured []interface{}) []string {
14 input := in.([]interface{}) 14 res := make([]string, len(configured))
15 res := make([]string, len(input))
16 15
17 for i, element := range input { 16 for i, element := range configured {
18 res[i] = element.(string) 17 res[i] = element.(string)
19 } 18 }
20 return res 19 return res
21} 20}
22 21
22// Special handling for node_locations since statuscake will return `[""]` for the empty case
23func considerEmptyStringAsEmptyArray(in []string) []string {
24 if len(in) == 1 && in[0] == "" {
25 return []string{}
26 } else {
27 return in
28 }
29}
30
23func resourceStatusCakeTest() *schema.Resource { 31func resourceStatusCakeTest() *schema.Resource {
24 return &schema.Resource{ 32 return &schema.Resource{
25 Create: CreateTest, 33 Create: CreateTest,
@@ -107,9 +115,10 @@ func resourceStatusCakeTest() *schema.Resource {
107 }, 115 },
108 116
109 "node_locations": { 117 "node_locations": {
110 Type: schema.TypeList, 118 Type: schema.TypeSet,
111 Elem: &schema.Schema{Type: schema.TypeString}, 119 Elem: &schema.Schema{Type: schema.TypeString},
112 Optional: true, 120 Optional: true,
121 Set: schema.HashString,
113 }, 122 },
114 123
115 "ping_url": { 124 "ping_url": {
@@ -123,8 +132,9 @@ func resourceStatusCakeTest() *schema.Resource {
123 }, 132 },
124 133
125 "basic_pass": { 134 "basic_pass": {
126 Type: schema.TypeString, 135 Type: schema.TypeString,
127 Optional: true, 136 Optional: true,
137 Sensitive: true,
128 }, 138 },
129 139
130 "public": { 140 "public": {
@@ -175,10 +185,6 @@ func resourceStatusCakeTest() *schema.Resource {
175 "status_codes": { 185 "status_codes": {
176 Type: schema.TypeString, 186 Type: schema.TypeString,
177 Optional: true, 187 Optional: true,
178 Default: "204, 205, 206, 303, 400, 401, 403, 404, 405, 406, " +
179 "408, 410, 413, 444, 429, 494, 495, 496, 499, 500, 501, 502, 503, " +
180 "504, 505, 506, 507, 508, 509, 510, 511, 521, 522, 523, 524, 520, " +
181 "598, 599",
182 }, 188 },
183 189
184 "use_jar": { 190 "use_jar": {
@@ -222,7 +228,7 @@ func CreateTest(d *schema.ResourceData, meta interface{}) error {
222 UserAgent: d.Get("user_agent").(string), 228 UserAgent: d.Get("user_agent").(string),
223 Status: d.Get("status").(string), 229 Status: d.Get("status").(string),
224 Uptime: d.Get("uptime").(float64), 230 Uptime: d.Get("uptime").(float64),
225 NodeLocations: castInterfaceToSliceStrings(d.Get("node_locations")), 231 NodeLocations: castSetToSliceStrings(d.Get("node_locations").(*schema.Set).List()),
226 PingURL: d.Get("ping_url").(string), 232 PingURL: d.Get("ping_url").(string),
227 BasicUser: d.Get("basic_user").(string), 233 BasicUser: d.Get("basic_user").(string),
228 BasicPass: d.Get("basic_pass").(string), 234 BasicPass: d.Get("basic_pass").(string),
@@ -308,24 +314,19 @@ func ReadTest(d *schema.ResourceData, meta interface{}) error {
308 d.Set("port", testResp.Port) 314 d.Set("port", testResp.Port)
309 d.Set("trigger_rate", testResp.TriggerRate) 315 d.Set("trigger_rate", testResp.TriggerRate)
310 d.Set("custom_header", testResp.CustomHeader) 316 d.Set("custom_header", testResp.CustomHeader)
311 d.Set("user_agent", testResp.UserAgent)
312 d.Set("status", testResp.Status) 317 d.Set("status", testResp.Status)
313 d.Set("uptime", testResp.Uptime) 318 d.Set("uptime", testResp.Uptime)
314 if err := d.Set("node_locations", testResp.NodeLocations); err != nil { 319 if err := d.Set("node_locations", considerEmptyStringAsEmptyArray(testResp.NodeLocations)); err != nil {
315 return fmt.Errorf("[WARN] Error setting node locations: %s", err) 320 return fmt.Errorf("[WARN] Error setting node locations: %s", err)
316 } 321 }
317 d.Set("ping_url", testResp.PingURL)
318 d.Set("basic_user", testResp.BasicUser)
319 d.Set("basic_pass", testResp.BasicPass)
320 d.Set("public", testResp.Public)
321 d.Set("logo_image", testResp.LogoImage) 322 d.Set("logo_image", testResp.LogoImage)
322 d.Set("branding", testResp.Branding) 323 // Even after WebsiteHost is set, the API returns ""
323 d.Set("website_host", testResp.WebsiteHost) 324 // API docs aren't clear on usage will only override state if we get a non-empty value back
324 d.Set("virus", testResp.Virus) 325 if testResp.WebsiteHost != "" {
326 d.Set("website_host", testResp.WebsiteHost)
327 }
325 d.Set("find_string", testResp.FindString) 328 d.Set("find_string", testResp.FindString)
326 d.Set("do_not_find", testResp.DoNotFind) 329 d.Set("do_not_find", testResp.DoNotFind)
327 d.Set("real_browser", testResp.RealBrowser)
328 d.Set("test_tags", testResp.TestTags)
329 d.Set("status_codes", testResp.StatusCodes) 330 d.Set("status_codes", testResp.StatusCodes)
330 d.Set("use_jar", testResp.UseJar) 331 d.Set("use_jar", testResp.UseJar)
331 d.Set("post_raw", testResp.PostRaw) 332 d.Set("post_raw", testResp.PostRaw)
@@ -380,7 +381,7 @@ func getStatusCakeTestInput(d *schema.ResourceData) *statuscake.Test {
380 test.UserAgent = v.(string) 381 test.UserAgent = v.(string)
381 } 382 }
382 if v, ok := d.GetOk("node_locations"); ok { 383 if v, ok := d.GetOk("node_locations"); ok {
383 test.NodeLocations = castInterfaceToSliceStrings(v) 384 test.NodeLocations = castSetToSliceStrings(v.(*schema.Set).List())
384 } 385 }
385 if v, ok := d.GetOk("ping_url"); ok { 386 if v, ok := d.GetOk("ping_url"); ok {
386 test.PingURL = v.(string) 387 test.PingURL = v.(string)