aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--statuscake/resource_statuscaketest.go25
-rw-r--r--statuscake/resource_statuscaketest_test.go3
2 files changed, 17 insertions, 11 deletions
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 (
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": {
@@ -219,7 +228,7 @@ func CreateTest(d *schema.ResourceData, meta interface{}) error {
219 UserAgent: d.Get("user_agent").(string), 228 UserAgent: d.Get("user_agent").(string),
220 Status: d.Get("status").(string), 229 Status: d.Get("status").(string),
221 Uptime: d.Get("uptime").(float64), 230 Uptime: d.Get("uptime").(float64),
222 NodeLocations: castInterfaceToSliceStrings(d.Get("node_locations")), 231 NodeLocations: castSetToSliceStrings(d.Get("node_locations").(*schema.Set).List()),
223 PingURL: d.Get("ping_url").(string), 232 PingURL: d.Get("ping_url").(string),
224 BasicUser: d.Get("basic_user").(string), 233 BasicUser: d.Get("basic_user").(string),
225 BasicPass: d.Get("basic_pass").(string), 234 BasicPass: d.Get("basic_pass").(string),
@@ -308,7 +317,7 @@ func ReadTest(d *schema.ResourceData, meta interface{}) error {
308 d.Set("user_agent", testResp.UserAgent) 317 d.Set("user_agent", testResp.UserAgent)
309 d.Set("status", testResp.Status) 318 d.Set("status", testResp.Status)
310 d.Set("uptime", testResp.Uptime) 319 d.Set("uptime", testResp.Uptime)
311 if err := d.Set("node_locations", testResp.NodeLocations); err != nil { 320 if err := d.Set("node_locations", considerEmptyStringAsEmptyArray(testResp.NodeLocations)); err != nil {
312 return fmt.Errorf("[WARN] Error setting node locations: %s", err) 321 return fmt.Errorf("[WARN] Error setting node locations: %s", err)
313 } 322 }
314 d.Set("ping_url", testResp.PingURL) 323 d.Set("ping_url", testResp.PingURL)
@@ -377,7 +386,7 @@ func getStatusCakeTestInput(d *schema.ResourceData) *statuscake.Test {
377 test.UserAgent = v.(string) 386 test.UserAgent = v.(string)
378 } 387 }
379 if v, ok := d.GetOk("node_locations"); ok { 388 if v, ok := d.GetOk("node_locations"); ok {
380 test.NodeLocations = castInterfaceToSliceStrings(v) 389 test.NodeLocations = castSetToSliceStrings(v.(*schema.Set).List())
381 } 390 }
382 if v, ok := d.GetOk("ping_url"); ok { 391 if v, ok := d.GetOk("ping_url"); ok {
383 test.PingURL = v.(string) 392 test.PingURL = v.(string)
diff --git a/statuscake/resource_statuscaketest_test.go b/statuscake/resource_statuscaketest_test.go
index 62d6bf9..555cff1 100644
--- a/statuscake/resource_statuscaketest_test.go
+++ b/statuscake/resource_statuscaketest_test.go
@@ -79,9 +79,6 @@ func TestAccStatusCake_withUpdate(t *testing.T) {
79 resource.TestCheckResourceAttr("statuscake_test.google", "status", "Up"), 79 resource.TestCheckResourceAttr("statuscake_test.google", "status", "Up"),
80 resource.TestCheckResourceAttr("statuscake_test.google", "uptime", "0"), 80 resource.TestCheckResourceAttr("statuscake_test.google", "uptime", "0"),
81 resource.TestCheckResourceAttr("statuscake_test.google", "node_locations.#", "3"), 81 resource.TestCheckResourceAttr("statuscake_test.google", "node_locations.#", "3"),
82 resource.TestCheckResourceAttr("statuscake_test.google", "node_locations.0", "string16045"),
83 resource.TestCheckResourceAttr("statuscake_test.google", "node_locations.1", "string19741"),
84 resource.TestCheckResourceAttr("statuscake_test.google", "node_locations.2", "string12122"),
85 resource.TestCheckResourceAttr("statuscake_test.google", "ping_url", "string8410"), 82 resource.TestCheckResourceAttr("statuscake_test.google", "ping_url", "string8410"),
86 resource.TestCheckResourceAttr("statuscake_test.google", "basic_user", "string27052"), 83 resource.TestCheckResourceAttr("statuscake_test.google", "basic_user", "string27052"),
87 resource.TestCheckResourceAttr("statuscake_test.google", "basic_pass", "string5659"), 84 resource.TestCheckResourceAttr("statuscake_test.google", "basic_pass", "string5659"),