Skip to content

Commit 710e76c

Browse files
committed
chore: let Terraform to manage UptimeRobot account
Fix #1301 [skip ci]
1 parent 08a07ce commit 710e76c

File tree

3 files changed

+61
-2
lines changed

3 files changed

+61
-2
lines changed

infra/terraform/README.md

+18-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
$ export HTTPS_PROXY=socks5://127.0.0.1:1122 # optionally
1818
$ terraform init
1919
```
20-
* Import existing configuration (optionally; only first time)
20+
* Import existing DigitalOcean configuration (optionally; only the first time)
2121
```console
2222
$ terraform import digitalocean_droplet.web <id>
2323
$ terraform import digitalocean_domain.site my-stamps.ru
@@ -43,6 +43,23 @@
4343
12345678
4444
$ curl -sS -H "Content-Type: application/json" -H "Authorization: Bearer $DIGITALOCEAN_TOKEN" "https://api.digitalocean.com/v2/domains/my-stamps.ru/records" | jq
4545
```
46+
* Import existing UptimeRobot configuration (optionally; only the first time)
47+
```console
48+
$ terraform import uptimerobot_alert_contact.email <id>
49+
$ terraform import uptimerobot_monitor.mystamps <id>
50+
$ terraform import uptimerobot_status_page.status_page <id>
51+
```
52+
The ids can be obtained by making `/v2/getAlertContacts`, `/v2/getMonitors`, and `/v2/getPSPs` API calls (see https://uptimerobot.com/api/ for details).
53+
For example:
54+
```console
55+
$ export UPTIMEROBOT_TOKEN="$(grep -Po 'uptimerobot_token = "\K[^\"]+' terraform.tfvars)"
56+
$ curl -sS -H 'Content-Type: application/x-www-form-urlencoded' -H 'Cache-Control: no-cache' -d "api_key=$UPTIMEROBOT_TOKEN" 'https://api.uptimerobot.com/v2/getAlertContacts' | jq -r '.alert_contacts[].id'
57+
1234567
58+
$ curl -sS -H 'Content-Type: application/x-www-form-urlencoded' -H 'Cache-Control: no-cache' -d "api_key=$UPTIMEROBOT_TOKEN" 'https://api.uptimerobot.com/v2/getMonitors' | jq '.monitors[].id'
59+
123456789
60+
$ curl -sS -H 'Content-Type: application/x-www-form-urlencoded' -H 'Cache-Control: no-cache' -d "api_key=$UPTIMEROBOT_TOKEN" 'https://api.uptimerobot.com/v2/getPSPs' | jq '.psps[].id'
61+
1234
62+
```
4663
* Plan and apply:
4764
```console
4865
$ terraform plan -out terraform.tfplan

infra/terraform/my-stamps.tf

+39-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# @todo #1000 CI: validate and check Terraform configuration
2-
# @todo #1000 Terraform: add UptimeRobot
32
# @todo #1000 Terraform: add Mailgun
43

54
variable "do_token" {
@@ -8,6 +7,15 @@ variable "do_token" {
87
type = string
98
}
109

10+
variable "uptimerobot_token" {
11+
# How to create API Key:
12+
# - open https://uptimerobot.com/dashboard
13+
# - go to MySettings
14+
# - scroll down to API Settings and select "Main API Key"
15+
description = "UptimeRobot API key"
16+
type = string
17+
}
18+
1119
# Digital Ocean provider docs: https://registry.terraform.io/providers/digitalocean/digitalocean/2.28.1/docs
1220
provider "digitalocean" {
1321
token = var.do_token
@@ -107,3 +115,33 @@ resource "digitalocean_record" "domain_key" {
107115
value = "k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDLo/TZgHYIM7xrU9dBJCJTTsP90rGhHuyTqSrC3LT+T3vsH5azrz1+9Dm86xz6TpcmrHV1WgmSnw72C++AXstlS8CEg6Z6XVuxMDKsMnMVEWDm1bpESy+h29Ns3kY/EzMTaF1V88ICmr6fSpQIOd9u/lZpsABjfh2wfag1rqWcGwIDAQAB"
108116
}
109117

118+
119+
# UptimeRobot provider docs: https://registry.terraform.io/providers/vexxhost/uptimerobot/0.8.2/docs
120+
provider "uptimerobot" {
121+
api_key = var.uptimerobot_token
122+
}
123+
124+
# https://registry.terraform.io/providers/vexxhost/uptimerobot/0.8.2/docs/resources/alert_contact
125+
resource "uptimerobot_alert_contact" "email" {
126+
127+
type = "e-mail"
128+
friendly_name = "[email protected]"
129+
}
130+
131+
# https://registry.terraform.io/providers/vexxhost/uptimerobot/0.8.2/docs/resources/monitor
132+
resource "uptimerobot_monitor" "mystamps" {
133+
url = "https://my-stamps.ru"
134+
type = "http"
135+
friendly_name = "MyStamps"
136+
interval = 300 # 300 seconds by default
137+
138+
alert_contact {
139+
id = uptimerobot_alert_contact.email.id
140+
}
141+
}
142+
143+
# https://registry.terraform.io/providers/vexxhost/uptimerobot/0.8.2/docs/resources/status_page
144+
resource "uptimerobot_status_page" "status_page" {
145+
friendly_name = "MyStamps Site Status"
146+
monitors = [ uptimerobot_monitor.mystamps.id ]
147+
}

infra/terraform/versions.tf

+4
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,9 @@ terraform {
77
source = "digitalocean/digitalocean"
88
version = "2.28.1"
99
}
10+
uptimerobot = {
11+
source = "vexxhost/uptimerobot"
12+
version = "0.8.2"
13+
}
1014
}
1115
}

0 commit comments

Comments
 (0)