Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
Merge branch 'master' of github.com:louy/terraform-provider-uptimerob…
Browse files Browse the repository at this point in the history
…ot into build-tags
  • Loading branch information
louy committed Aug 27, 2018
2 parents 149d992 + d5d7704 commit 980f484
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# v0.2.0
- resource monitor: add support for interval attribute (#7)
- resource alert_contact: remove ForceNew on url (#12)
- various documentation updates (#8, #10)

# v0.1.1
- Fix a bug in resourceMonitorUpdate (#5)
- Fix a crash in resourceMonitorGet when the monitor doesn't exist (#6)
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,20 @@ provider "uptimerobot" {
resource "uptimerobot_alert_contact" "slack" {
friendly_name = "Slack Alert"
type = "slack"
webhook_url = "https://hooks.slack.com/services/XXXXXXX"
value = "https://hooks.slack.com/services/XXXXXXX"
}
resource "uptimerobot_monitor" "main" {
friendly_name = "My Monitor"
type = "http"
url = "http://example.com"
# pro allows 60 seconds
interval = 300
alert_contact {
id = "${resource.uptimerobot_alert_contact.slack.id}"
# threshold = 0
# recurrence = 0
# threshold = 0 # pro only
# recurrence = 0 # pro only
}
}
Expand Down
2 changes: 2 additions & 0 deletions uptimerobot/api/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand Down Expand Up @@ -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]))
Expand Down
9 changes: 8 additions & 1 deletion uptimerobot/resource_uptimerobot_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ func resourceMonitor() *schema.Resource {
"url": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"type": {
Type: schema.TypeString,
Expand Down Expand Up @@ -127,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{
Expand Down Expand Up @@ -189,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{
Expand Down
110 changes: 110 additions & 0 deletions uptimerobot/resource_uptimerobot_monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,59 @@ func TestUptimeRobotDataResourceMonitor_http_monitor(t *testing.T) {
})
}

func TestUptimeRobotDataResourceMonitor_change_url(t *testing.T) {
var FriendlyName = "TF Test: http monitor"
var Type = "http"
var URL = "https://google.com"
var URL2 = "https://google.co.uk"
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,
},
// Change url
resource.TestStep{
Config: fmt.Sprintf(`
resource "uptimerobot_monitor" "test" {
friendly_name = "%s"
type = "%s"
url = "%s"
}
`, FriendlyName, Type, URL2),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("uptimerobot_monitor.test", "friendly_name", FriendlyName),
resource.TestCheckResourceAttr("uptimerobot_monitor.test", "type", Type),
resource.TestCheckResourceAttr("uptimerobot_monitor.test", "url", URL2),
),
},
resource.TestStep{
ResourceName: "uptimerobot_monitor.test",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestUptimeRobotDataResourceMonitor_ping_monitor(t *testing.T) {
var FriendlyName = "TF Test: ping monitor"
var Type = "ping"
Expand Down Expand Up @@ -75,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"
Expand Down
12 changes: 8 additions & 4 deletions website/docs/index.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ description: |-
---

# UptimeRobot Provider
The UptimeRobot provider is used to interact with the resources supported by UptimeRobot. The provider needs to be configured with the proper credentials before it can be used.
The [UptimeRobot]((https://uptimerobot.com/) provider is used to interact with the resources supported by UptimeRobot. The provider needs to be configured with the proper credentials before it can be used.
Use the navigation to the left to read about the available resources.

## Example Usage
Expand All @@ -29,8 +29,12 @@ resource "uptimerobot_monitor" "web" {
## Authentication
The UptimeRobot provider needs an account-specific (main) api key to work. You can find that key for your account in the [My Settings](https://uptimerobot.com/dashboard#mySettings) page on UptimeRobot's website.

## Argument Reference
## Configuration Reference

The following arguments are supported in the `provider` block:
The following keys can be used to configure the provider.

* `api_key` - (Required) UptimeRobot's account-specific api key.
* `api_key` - (optional) UptimeRobot's account-specific api key.

Credentials can also be specified using any of the following environment variables (listed in order of precedence):

* `UPTIMEROBOT_API_KEY`

0 comments on commit 980f484

Please sign in to comment.