diff --git a/uptimerobot/api/monitor.go b/uptimerobot/api/monitor.go index ce324fa..6fbcc15 100644 --- a/uptimerobot/api/monitor.go +++ b/uptimerobot/api/monitor.go @@ -140,6 +140,7 @@ func (client UptimeRobotApiClient) CreateMonitor(req MonitorCreateRequest) (m Mo data.Add("friendly_name", req.FriendlyName) data.Add("url", req.URL) data.Add("type", fmt.Sprintf("%d", monitorType[req.Type])) + data.Add("interval", fmt.Sprintf("%d", req.Interval)) switch req.Type { case "port": data.Add("sub_type", fmt.Sprintf("%d", monitorSubType[req.SubType])) @@ -202,6 +203,7 @@ func (client UptimeRobotApiClient) UpdateMonitor(req MonitorUpdateRequest) (m Mo data.Add("friendly_name", req.FriendlyName) data.Add("url", req.URL) data.Add("type", fmt.Sprintf("%d", monitorType[req.Type])) + data.Add("interval", fmt.Sprintf("%d", req.Interval)) switch req.Type { case "port": data.Add("sub_type", fmt.Sprintf("%d", monitorSubType[req.SubType])) diff --git a/uptimerobot/resource_uptimerobot_monitor.go b/uptimerobot/resource_uptimerobot_monitor.go index 838914a..bb2a64f 100644 --- a/uptimerobot/resource_uptimerobot_monitor.go +++ b/uptimerobot/resource_uptimerobot_monitor.go @@ -126,6 +126,10 @@ func resourceMonitorCreate(d *schema.ResourceData, m interface{}) error { req.HTTPPassword = d.Get("http_password").(string) break } + + // Add optional attributes + req.Interval = d.Get("interval").(int) + req.AlertContacts = make([]uptimerobotapi.MonitorRequestAlertContact, len(d.Get("alert_contact").([]interface{}))) for k, v := range d.Get("alert_contact").([]interface{}) { req.AlertContacts[k] = uptimerobotapi.MonitorRequestAlertContact{ @@ -188,6 +192,10 @@ func resourceMonitorUpdate(d *schema.ResourceData, m interface{}) error { req.HTTPPassword = d.Get("http_password").(string) break } + + // Add optional attributes + req.Interval = d.Get("interval").(int) + req.AlertContacts = make([]uptimerobotapi.MonitorRequestAlertContact, len(d.Get("alert_contact").([]interface{}))) for k, v := range d.Get("alert_contact").([]interface{}) { req.AlertContacts[k] = uptimerobotapi.MonitorRequestAlertContact{ diff --git a/uptimerobot/resource_uptimerobot_monitor_test.go b/uptimerobot/resource_uptimerobot_monitor_test.go index 0f76811..5917158 100644 --- a/uptimerobot/resource_uptimerobot_monitor_test.go +++ b/uptimerobot/resource_uptimerobot_monitor_test.go @@ -12,6 +12,38 @@ import ( ) func TestUptimeRobotDataResourceMonitor_http_monitor(t *testing.T) { + var FriendlyName = "TF Test: http monitor" + var Type = "http" + var URL = "https://google.com" + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckMonitorDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: fmt.Sprintf(` + resource "uptimerobot_monitor" "test" { + friendly_name = "%s" + type = "%s" + url = "%s" + } + `, FriendlyName, Type, URL), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("uptimerobot_monitor.test", "friendly_name", FriendlyName), + resource.TestCheckResourceAttr("uptimerobot_monitor.test", "type", Type), + resource.TestCheckResourceAttr("uptimerobot_monitor.test", "url", URL), + ), + }, + resource.TestStep{ + ResourceName: "uptimerobot_monitor.test", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestUptimeRobotDataResourceMonitor_change_url(t *testing.T) { var FriendlyName = "TF Test: http monitor" var Type = "http" var URL = "https://google.com" @@ -23,7 +55,8 @@ func TestUptimeRobotDataResourceMonitor_http_monitor(t *testing.T) { Steps: []resource.TestStep{ resource.TestStep{ Config: fmt.Sprintf(` - resource "uptimerobot_monitor" "test" { friendly_name = "%s" + resource "uptimerobot_monitor" "test" { + friendly_name = "%s" type = "%s" url = "%s" } @@ -42,7 +75,8 @@ func TestUptimeRobotDataResourceMonitor_http_monitor(t *testing.T) { // Change url resource.TestStep{ Config: fmt.Sprintf(` - resource "uptimerobot_monitor" "test" { friendly_name = "%s" + resource "uptimerobot_monitor" "test" { + friendly_name = "%s" type = "%s" url = "%s" } @@ -94,6 +128,63 @@ func TestUptimeRobotDataResourceMonitor_ping_monitor(t *testing.T) { }) } +func TestUptimeRobotDataResourceMonitor_custom_interval(t *testing.T) { + var FriendlyName = "TF Test: ping monitor" + var Type = "ping" + var URL = "1.1.1.1" + var Interval = 300 + var Interval2 = 360 + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckMonitorDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: fmt.Sprintf(` + resource "uptimerobot_monitor" "test" { + friendly_name = "%s" + type = "%s" + url = "%s" + interval = %d + } + `, FriendlyName, Type, URL, Interval), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("uptimerobot_monitor.test", "friendly_name", FriendlyName), + resource.TestCheckResourceAttr("uptimerobot_monitor.test", "type", Type), + resource.TestCheckResourceAttr("uptimerobot_monitor.test", "url", URL), + resource.TestCheckResourceAttr("uptimerobot_monitor.test", "interval", fmt.Sprintf(`%d`, Interval)), + ), + }, + resource.TestStep{ + ResourceName: "uptimerobot_monitor.test", + ImportState: true, + ImportStateVerify: true, + }, + resource.TestStep{ + Config: fmt.Sprintf(` + resource "uptimerobot_monitor" "test" { + friendly_name = "%s" + type = "%s" + url = "%s" + interval = %d + } + `, FriendlyName, Type, URL, Interval2), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("uptimerobot_monitor.test", "friendly_name", FriendlyName), + resource.TestCheckResourceAttr("uptimerobot_monitor.test", "type", Type), + resource.TestCheckResourceAttr("uptimerobot_monitor.test", "url", URL), + resource.TestCheckResourceAttr("uptimerobot_monitor.test", "interval", fmt.Sprintf(`%d`, Interval2)), + ), + }, + resource.TestStep{ + ResourceName: "uptimerobot_monitor.test", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func TestUptimeRobotDataResourceMonitor_http_auth_monitor(t *testing.T) { var FriendlyName = "TF Test: http auth monitor" var Type = "http"