-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: datadog-synthetics-monitor + checks
- Loading branch information
1 parent
cdbcac6
commit 8edc4d2
Showing
11 changed files
with
426 additions
and
0 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* @gorillamoe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
changelog: | ||
exclude: | ||
labels: | ||
- ignore-for-release | ||
categories: | ||
- title: Breaking Changes 💥 | ||
labels: | ||
- breaking-change | ||
- title: Documentation 📚 | ||
labels: | ||
- documentation | ||
- title: Exciting New Features ✨ | ||
labels: | ||
- enhancement | ||
- title: Bug Fixes 🐛 | ||
labels: | ||
- bug |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--- | ||
name: Checker 😎 | ||
|
||
on: [pull_request, push] | ||
|
||
jobs: | ||
pr-checker: | ||
name: Checker 😎 | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout & Setup Tofu | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- uses: opentofu/setup-opentofu@v1 | ||
with: | ||
tofu_version: 1.8.1 | ||
- name: Check if tofu files are correctly formatted | ||
run: ./scripts/check-tofu-format.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
--- | ||
name: Release | ||
|
||
on: | ||
push: | ||
tags: | ||
- 'v[0-9]+.[0-9]+.[0-9]+' | ||
jobs: | ||
create-release: | ||
name: Create Release | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- name: Set up env | ||
run: | | ||
VERSION=${GITHUB_REF_NAME#v} | ||
echo "VERSION=$VERSION" >> $GITHUB_ENV | ||
- name: Create Release | ||
run: ./scripts/release.sh | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
*.tfstate | ||
.terraform | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
extends: default | ||
rules: | ||
truthy: | ||
check-keys: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
# Opentofu Module Datadog Synthetics Monitor | ||
|
||
A Opentofu module to create a Datadog 🐶 Synthetics Monitor. | ||
|
||
## Usage | ||
|
||
There are three operating modes: `test_browser`, `test_api`, `test_api/ssl`. | ||
|
||
- to choose `test_api` mode you should pass variables (`synthetics_type=api` and `synthetics_subtype=http`) | ||
- to choose `test_api/ssl` mode you should pass variables (`synthetics_type=api` and `synthetics_subtype=ssl`) | ||
- to choose `browser test`(it runs by default in minimal configuration) you should pass variable (`synthetics_type=browser`) | ||
|
||
|
||
### Minimal | ||
|
||
A minimal example to create a Datadog Synthetics Monitor. | ||
|
||
```terraform | ||
module "datadog_synthetics" { | ||
source = "github.com/mistweaverco/opentofu-modules/modules/datadog-synthetics-monitor" | ||
dd_api_key = "Datadog API Key" | ||
dd_app_key = "Datadog APP Key" | ||
env = "production" | ||
name = "mistweaverco.co Frontend Test" | ||
service_name = "mistweaverco.co" | ||
synthetics_url = "https://mistweaverco.co" | ||
notification_targets = [ | ||
"@slack-alerts", | ||
"@[email protected]" | ||
] | ||
} | ||
``` | ||
|
||
### Full | ||
|
||
A full example to create a Datadog Synthetics Monitor. | ||
|
||
```terraform | ||
module "datadog_synthetics" { | ||
source = "github.com/mistweaverco/opentofu-modules/modules/datadog-synthetics-monitor" | ||
enabled = true | ||
dd_api_key = "Datadog API Key" | ||
dd_app_key = "Datadog APP Key" | ||
env = "production" | ||
name = "mistweaverco.co Frontend Test" | ||
service_name = "mistweaverco.co" | ||
synthetics_url = "https://mistweaverco.co" | ||
synthetics_type = "browser" | ||
synthetics_subtype = "laptop_large" | ||
synthetics_locations = ["gcp:europe-west3"] | ||
synthetics_device_ids = ["laptop_large"] | ||
browser_request_frequency = 300 | ||
synthetics_alert_down_message = "There are some problems on:" | ||
synthetics_alert_up_message = "The problems are gone on:" | ||
api_request_frequency = 60 | ||
api_assertion_type = "statusCode" | ||
api_assertion_operator = "is" | ||
api_assertion_target = "200" | ||
synthetics_ssl_port = "443" | ||
synthetics_ssl_request_frequency = 900 | ||
synthetics_ssl_accept_self_signed = true | ||
ssl_assertion_type = "certificate" | ||
ssl_assertion_operator = "isInMoreThan" | ||
ssl_assertion_target = 30 | ||
synthetics_status = "live" | ||
notification_targets = [ | ||
"@slack-alerts", | ||
"@[email protected]" | ||
] | ||
} | ||
``` | ||
|
||
### Inputs | ||
|
||
| Name | Description | Type | Default | Required | | ||
|------|-------------|------|---------|:--------:| | ||
| <a name="input_api_assertion_operator"></a> [api\_assertion\_operator](#input\_api\_assertion\_operator) | n/a | `string` | `"is"` | no | | ||
| <a name="input_api_assertion_target"></a> [api\_assertion\_target](#input\_api\_assertion\_target) | n/a | `string` | `"200"` | no | | ||
| <a name="input_api_assertion_type"></a> [api\_assertion\_type](#input\_api\_assertion\_type) | n/a | `string` | `"statusCode"` | no | | ||
| <a name="input_api_request_frequency"></a> [api\_request\_frequency](#input\_api\_request\_frequency) | n/a | `number` | `60` | no | | ||
| <a name="input_browser_request_frequency"></a> [browser\_request\_frequency](#input\_browser\_request\_frequency) | n/a | `number` | `300` | no | | ||
| <a name="input_dd_api_key"></a> [dd\_api\_key](#input\_dd\_api\_key) | Datadog API Key. You can find out how to get it here: https://docs.datadoghq.com/account_management/api-app-keys/ | `any` | n/a | yes | | ||
| <a name="input_dd_app_key"></a> [dd\_app\_key](#input\_dd\_app\_key) | Datadog APP Key. You can find out how to get it here: https://docs.datadoghq.com/account_management/api-app-keys/ | `any` | n/a | yes | | ||
| <a name="input_enabled"></a> [enabled](#input\_enabled) | n/a | `bool` | `true` | no | | ||
| <a name="input_env"></a> [env](#input\_env) | n/a | `any` | n/a | yes | | ||
| <a name="input_name"></a> [name](#input\_name) | n/a | `any` | n/a | yes | | ||
| <a name="input_notification_targets"></a> [notification\_targets](#input\_notification\_targets) | List of targets to inform. For example it could be @slack-alerts or @user:marco@mistweaverco.co. For more info visit https://docs.datadoghq.com/monitors/notifications/?tab=is_alert#notifications | `list` | n/a | yes | | ||
| <a name="input_service_name"></a> [service\_name](#input\_service\_name) | n/a | `any` | n/a | yes | | ||
| <a name="input_ssl_assertion_operator"></a> [ssl\_assertion\_operator](#input\_ssl\_assertion\_operator) | n/a | `string` | `"isInMoreThan"` | no | | ||
| <a name="input_ssl_assertion_target"></a> [ssl\_assertion\_target](#input\_ssl\_assertion\_target) | n/a | `number` | `30` | no | | ||
| <a name="input_ssl_assertion_type"></a> [ssl\_assertion\_type](#input\_ssl\_assertion\_type) | n/a | `string` | `"certificate"` | no | | ||
| <a name="input_synthetics_alert_down_message"></a> [synthetics\_alert\_down\_message](#input\_synthetics\_alert\_down\_message) | n/a | `string` | `"There are some problems on:"` | no | | ||
| <a name="input_synthetics_alert_up_message"></a> [synthetics\_alert\_up\_message](#input\_synthetics\_alert\_up\_message) | n/a | `string` | `"The problems are gone on:"` | no | | ||
| <a name="input_synthetics_device_ids"></a> [synthetics\_device\_ids](#input\_synthetics\_device\_ids) | n/a | `list` | <pre>[<br> "laptop_large"<br>]</pre> | no | | ||
| <a name="input_synthetics_locations"></a> [synthetics\_locations](#input\_synthetics\_locations) | n/a | `list` | <pre>[<br> "gcp:europe-west3"<br>]</pre> | no | | ||
| <a name="input_synthetics_ssl_accept_self_signed"></a> [synthetics\_ssl\_accept\_self\_signed](#input\_synthetics\_ssl\_accept\_self\_signed) | n/a | `bool` | `true` | no | | ||
| <a name="input_synthetics_ssl_port"></a> [synthetics\_ssl\_port](#input\_synthetics\_ssl\_port) | n/a | `string` | `"443"` | no | | ||
| <a name="input_synthetics_ssl_request_frequency"></a> [synthetics\_ssl\_request\_frequency](#input\_synthetics\_ssl\_request\_frequency) | n/a | `number` | `900` | no | | ||
| <a name="input_synthetics_status"></a> [synthetics\_status](#input\_synthetics\_status) | n/a | `string` | `"live"` | no | | ||
| <a name="input_synthetics_subtype"></a> [synthetics\_subtype](#input\_synthetics\_subtype) | n/a | `string` | `"http"` | no | | ||
| <a name="input_synthetics_type"></a> [synthetics\_type](#input\_synthetics\_type) | n/a | `string` | `"browser"` | no | | ||
| <a name="input_synthetics_url"></a> [synthetics\_url](#input\_synthetics\_url) | n/a | `any` | n/a | yes | | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
terraform { | ||
required_providers { | ||
datadog = { | ||
source = "DataDog/datadog" | ||
} | ||
} | ||
} | ||
|
||
provider "datadog" { | ||
api_key = var.dd_api_key | ||
app_key = var.dd_app_key | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
resource "datadog_synthetics_test" "browser" { | ||
count = (var.enabled && var.synthetics_type == "browser") ? 1 : 0 | ||
name = var.name | ||
type = "browser" | ||
request_definition { | ||
method = "GET" | ||
url = var.synthetics_url | ||
} | ||
device_ids = var.synthetics_device_ids | ||
locations = var.synthetics_locations | ||
options_list { | ||
tick_every = var.browser_request_frequency | ||
} | ||
message = <<EOM | ||
{{#is_no_data}}Monitor doesn't have data on ${var.synthetics_url}{{/is_no_data}} | ||
{{#is_alert}}${var.synthetics_alert_down_message} ${var.synthetics_url}{{/is_alert}} | ||
{{^is_alert}}${var.synthetics_alert_up_message} ${var.synthetics_url}{{/is_alert}} | ||
${join(" ", var.notification_targets)} | ||
EOM | ||
tags = [ | ||
"env:${var.env}", | ||
"service:${var.service_name}", | ||
"terraform:true" | ||
] | ||
status = var.synthetics_status | ||
} | ||
|
||
resource "datadog_synthetics_test" "api" { | ||
count = (var.enabled && var.synthetics_type == "api" && var.synthetics_subtype == "http") ? 1 : 0 | ||
name = var.name | ||
type = var.synthetics_type | ||
subtype = var.synthetics_subtype | ||
request_definition { | ||
method = "GET" | ||
url = var.synthetics_url | ||
} | ||
assertion { | ||
type = var.api_assertion_type | ||
operator = var.api_assertion_operator | ||
target = var.api_assertion_target | ||
} | ||
locations = var.synthetics_locations | ||
options_list { | ||
tick_every = var.browser_request_frequency | ||
} | ||
message = <<EOM | ||
{{#is_no_data}}Monitor doesn't have data on ${var.synthetics_url}{{/is_no_data}} | ||
{{#is_alert}}${var.synthetics_alert_down_message} ${var.synthetics_url}{{/is_alert}} | ||
{{^is_alert}}${var.synthetics_alert_up_message} ${var.synthetics_url}{{/is_alert}} | ||
${join(" ", var.notification_targets)} | ||
EOM | ||
tags = [ | ||
"env:${var.env}", | ||
"service:${var.service_name}", | ||
"terraform:true" | ||
] | ||
status = var.synthetics_status | ||
} | ||
|
||
resource "datadog_synthetics_test" "ssl" { | ||
count = (var.enabled && var.synthetics_type == "api" && var.synthetics_subtype == "ssl") ? 1 : 0 | ||
name = var.name | ||
type = var.synthetics_type | ||
subtype = var.synthetics_subtype | ||
request_definition { | ||
host = var.synthetics_url | ||
port = var.synthetics_ssl_port | ||
} | ||
assertion { | ||
type = var.ssl_assertion_type | ||
operator = var.ssl_assertion_operator | ||
target = var.ssl_assertion_target | ||
} | ||
locations = var.synthetics_locations | ||
options_list { | ||
tick_every = var.synthetics_ssl_request_frequency | ||
accept_self_signed = var.synthetics_ssl_accept_self_signed | ||
} | ||
message = <<EOM | ||
{{#is_no_data}}Monitor doesn't have data on ${var.synthetics_url}{{/is_no_data}} | ||
{{#is_alert}}${var.synthetics_alert_down_message} ${var.synthetics_url}{{/is_alert}} | ||
{{^is_alert}}${var.synthetics_alert_up_message} ${var.synthetics_url}{{/is_alert}} | ||
${join(" ", var.notification_targets)} | ||
EOM | ||
tags = [ | ||
"env:${var.env}", | ||
"service:${var.service_name}", | ||
"terraform:true" | ||
] | ||
status = var.synthetics_status | ||
} |
Oops, something went wrong.