Skip to content

Commit

Permalink
Merge pull request #229 from eravin-ns1/region-sets
Browse files Browse the repository at this point in the history
use non-ordered set for monitoring region list
  • Loading branch information
eravin-ns1 authored Oct 6, 2022
2 parents 7cfa306 + 3ae45ce commit bdd5671
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
10 changes: 3 additions & 7 deletions ns1/resource_monitoringjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"log"
"regexp"
"sort"
"strconv"
"strings"

Expand All @@ -28,7 +27,7 @@ func monitoringJobResource() *schema.Resource {
ForceNew: true,
},
"regions": {
Type: schema.TypeList,
Type: schema.TypeSet,
Required: true,
Elem: &schema.Schema{
Type: schema.TypeString,
Expand Down Expand Up @@ -130,10 +129,7 @@ func monitoringJobToResourceData(d *schema.ResourceData, r *monitor.Job) error {
d.Set("job_type", r.Type)
d.Set("active", r.Active)
d.Set("mute", r.Mute)
if len(r.Regions) > 0 {
sort.Strings(r.Regions)
d.Set("regions", r.Regions)
}
d.Set("regions", r.Regions)
d.Set("frequency", r.Frequency)
d.Set("rapid_recheck", r.RapidRecheck)
config := make(map[string]string)
Expand Down Expand Up @@ -191,7 +187,7 @@ func resourceDataToMonitoringJob(r *monitor.Job, d *schema.ResourceData) error {
r.Type = d.Get("job_type").(string)
r.Active = d.Get("active").(bool)
r.Mute = d.Get("mute").(bool)
rawRegions := d.Get("regions").([]interface{})
rawRegions := d.Get("regions").(*schema.Set).List()
r.Regions = make([]string, len(rawRegions))
for i, v := range rawRegions {
r.Regions[i] = v.(string)
Expand Down
6 changes: 3 additions & 3 deletions ns1/resource_monitoringjob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestAccMonitoringJob_basic(t *testing.T) {
testAccCheckMonitoringJobExists("ns1_monitoringjob.it", &mj),
testAccCheckMonitoringJobName(&mj, "terraform test"),
testAccCheckMonitoringJobActive(&mj, true),
testAccCheckMonitoringJobRegions(&mj, []string{"lga", "sjc", "sin"}),
testAccCheckMonitoringJobRegions(&mj, []string{"lga", "sjc", "nrt"}),
testAccCheckMonitoringJobType(&mj, "tcp"),
testAccCheckMonitoringJobFrequency(&mj, 60),
testAccCheckMonitoringJobRapidRecheck(&mj, false),
Expand All @@ -46,7 +46,7 @@ func TestAccMonitoringJob_basic(t *testing.T) {
testAccCheckMonitoringJobExists("ns1_monitoringjob.it", &mj),
testAccCheckMonitoringJobName(&mj, "terraform http test"),
testAccCheckMonitoringJobActive(&mj, true),
testAccCheckMonitoringJobRegions(&mj, []string{"lga", "sjc", "sin"}),
testAccCheckMonitoringJobRegions(&mj, []string{"lga", "sjc", "lhr"}),
testAccCheckMonitoringJobType(&mj, "http"),
testAccCheckMonitoringJobFrequency(&mj, 60),
testAccCheckMonitoringJobRapidRecheck(&mj, false),
Expand All @@ -71,7 +71,7 @@ func TestAccMonitoringJob_updated(t *testing.T) {
testAccCheckMonitoringJobExists("ns1_monitoringjob.it", &mj),
testAccCheckMonitoringJobName(&mj, "terraform test"),
testAccCheckMonitoringJobActive(&mj, true),
testAccCheckMonitoringJobRegions(&mj, []string{"lga", "sjc", "sin"}),
testAccCheckMonitoringJobRegions(&mj, []string{"nrt", "sjc", "sin"}),
testAccCheckMonitoringJobType(&mj, "tcp"),
testAccCheckMonitoringJobFrequency(&mj, 60),
testAccCheckMonitoringJobRapidRecheck(&mj, false),
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/monitoringjob.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ The following arguments are supported:
* `job_type` - (Required) The type of monitoring job to be run. Refer to the NS1 API documentation (https://ns1.com/api#monitoring-jobs) for supported values which include ping, tcp, dns, http.
* `active` - (Required) Indicates if the job is active or temporarily disabled.
* `regions` - (Required) The list of region codes in which to run the monitoring
job. See NS1 API docs for supported values. NOTE: order alphabetically by region code.
job. See NS1 API docs for supported values.
* `frequency` - (Required) The frequency, in seconds, at which to run the monitoring job in each region.
* `rapid_recheck` - (Required) If true, on any apparent state change, the job is quickly re-run after one second to confirm the state change before notification.
* `policy` - (Required) The policy for determining the monitor's global status
Expand Down

0 comments on commit bdd5671

Please sign in to comment.