"github.com/hashicorp/terraform/helper/schema"
)
+func castSetToSliceStrings(configured []interface{}) []string {
+ res := make([]string, len(configured))
+
+ 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,
},
"contact_id": {
- Type: schema.TypeString,
+ Type: schema.TypeInt,
Optional: true,
},
},
"node_locations": {
- Type: schema.TypeList,
+ Type: schema.TypeSet,
Elem: &schema.Schema{Type: schema.TypeString},
Optional: true,
+ Set: schema.HashString,
},
"ping_url": {
},
"basic_pass": {
- Type: schema.TypeString,
- Optional: true,
+ Type: schema.TypeString,
+ Optional: true,
+ Sensitive: true,
},
"public": {
"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": {
TestType: d.Get("test_type").(string),
Paused: d.Get("paused").(bool),
Timeout: d.Get("timeout").(int),
- ContactID: d.Get("contact_id").(string),
+ ContactID: d.Get("contact_id").(int),
Confirmation: d.Get("confirmations").(int),
Port: d.Get("port").(int),
TriggerRate: d.Get("trigger_rate").(int),
UserAgent: d.Get("user_agent").(string),
Status: d.Get("status").(string),
Uptime: d.Get("uptime").(float64),
- NodeLocations: d.Get("node_locations").([]string),
+ 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),
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)
+ if err := d.Set("node_locations", considerEmptyStringAsEmptyArray(testResp.NodeLocations)); err != nil {
+ return fmt.Errorf("[WARN] Error setting node locations: %s", err)
+ }
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)
test.CheckRate = v.(int)
}
if v, ok := d.GetOk("contact_id"); ok {
- test.ContactID = v.(string)
+ test.ContactID = v.(int)
}
if v, ok := d.GetOk("test_type"); ok {
test.TestType = v.(string)
test.UserAgent = v.(string)
}
if v, ok := d.GetOk("node_locations"); ok {
- test.NodeLocations = v.([]string)
+ test.NodeLocations = castSetToSliceStrings(v.(*schema.Set).List())
}
if v, ok := d.GetOk("ping_url"); ok {
test.PingURL = v.(string)