Skip to content

Commit

Permalink
Merge pull request #3 from rhythmictech/ENG-4007
Browse files Browse the repository at this point in the history
configure ssl certificate monitor
  • Loading branch information
lalo-galvan committed Aug 21, 2024
2 parents 713962e + ded9b2e commit e342e79
Show file tree
Hide file tree
Showing 13 changed files with 510 additions and 0 deletions.
7 changes: 7 additions & 0 deletions common/common.tf
Original file line number Diff line number Diff line change
Expand Up @@ -255,5 +255,12 @@ ${local.alert_context}
{{#is_warning}} ${local.notify_on_warn} {{/is_warning}}
{{#is_no_data}} ${local.notify_on_nodata} {{/is_no_data}}
{{#is_recovery}} ${local.notify_on_recovery} {{/is_recovery}}
END

synthetic_alert_base_message = <<END
${local.alert_context}
**Alert Information**
{{#is_alert}} ${local.notify_on_alert} {{/is_alert}}
{{#is_recovery}} ${local.notify_on_recovery} {{/is_recovery}}
END
}
44 changes: 44 additions & 0 deletions synthetics/browser/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

70 changes: 70 additions & 0 deletions synthetics/browser/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# terraform-datadog-monitor/synthetics/browser

Configures Synthetic Test for Browser

<!-- BEGIN_TF_DOCS -->
## Requirements

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | ~> 1.5 |
| <a name="requirement_datadog"></a> [datadog](#requirement\_datadog) | >= 3.37 |
| <a name="requirement_null"></a> [null](#requirement\_null) | >= 3.1.0 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_datadog"></a> [datadog](#provider\_datadog) | 3.42.0 |

## Modules

No modules.

## Resources

| Name | Type |
|------|------|
| [datadog_synthetics_test.browser](https://registry.terraform.io/providers/datadog/datadog/latest/docs/resources/synthetics_test) | resource |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_additional_tags"></a> [additional\_tags](#input\_additional\_tags) | Additional tags (key:value format) to add to this type of check (combined with `local.tags` and `var.base_tags`) | `list(string)` | `[]` | no |
| <a name="input_alert_critical_priority"></a> [alert\_critical\_priority](#input\_alert\_critical\_priority) | Priority for alerts within critical threshold (P1-P5, uses monitor defaults if not specified) | `string` | `null` | no |
| <a name="input_alert_message"></a> [alert\_message](#input\_alert\_message) | Message to prepend to alert notifications | `string` | `"Alert"` | no |
| <a name="input_alert_nodata_priority"></a> [alert\_nodata\_priority](#input\_alert\_nodata\_priority) | Priority for alerts within warning threshold (P1-P5, uses monitor defaults if not specified) | `string` | `null` | no |
| <a name="input_base_tags"></a> [base\_tags](#input\_base\_tags) | Base tags (key:value format) to add to this type of check (combined with `local.tags` and `var.additional_tags`, generally you should not change this) | `list(string)` | <pre>[<br> "resource:apigateway"<br>]</pre> | no |
| <a name="input_browser_synthetic_device_ids"></a> [browser\_synthetic\_device\_ids](#input\_browser\_synthetic\_device\_ids) | List with the different device IDs used to run the test. Valid values are laptop\_large, tablet, mobile\_small, chrome.laptop\_large, chrome.tablet, chrome.mobile\_small, firefox.laptop\_large, firefox.tablet, firefox.mobile\_small, edge.laptop\_large, edge.tablet, edge.mobile\_small. | `list(string)` | <pre>[<br> "laptop_large"<br>]</pre> | no |
| <a name="input_browser_synthetic_enabled"></a> [browser\_synthetic\_enabled](#input\_browser\_synthetic\_enabled) | Flag to enable Browser Synthetic Test. | `bool` | `true` | no |
| <a name="input_browser_synthetic_locations"></a> [browser\_synthetic\_locations](#input\_browser\_synthetic\_locations) | An array of datadog locations used to run Browser Synthetic Test. | `list(string)` | <pre>[<br> "aws:us-east-1"<br>]</pre> | no |
| <a name="input_browser_synthetic_request_url"></a> [browser\_synthetic\_request\_url](#input\_browser\_synthetic\_request\_url) | URL to send Browser Synthetic Test requests to. | `string` | n/a | yes |
| <a name="input_browser_synthetic_steps"></a> [browser\_synthetic\_steps](#input\_browser\_synthetic\_steps) | Steps for the Browser Synthetic Test to take. | <pre>list(object({<br> name = string<br> type = string<br> params = object({<br> attribute = optional(string)<br> check = optional(string)<br> click_type = optional(string)<br> code = optional(string)<br> delay = optional(number)<br> element = optional(string)<br> element_user_locator = optional(map(string))<br> email = optional(string)<br> file = optional(string)<br> files = optional(string)<br> modifiers = optional(list(string))<br> playing_tab_id = optional(string)<br> request = optional(string)<br> subtest_public_id = optional(string)<br> value = optional(string)<br> variable = optional(map(string))<br> with_click = optional(bool)<br> x = optional(number)<br> y = optional(number)<br> })<br> }))</pre> | n/a | yes |
| <a name="input_browser_synthetic_tick_every"></a> [browser\_synthetic\_tick\_every](#input\_browser\_synthetic\_tick\_every) | How often Browser Synthetic Test should run in seconds. | `number` | `900` | no |
| <a name="input_cost_center"></a> [cost\_center](#input\_cost\_center) | Cost Center of the monitored resource (leave blank to omit tag) | `string` | `null` | no |
| <a name="input_dashboard_link"></a> [dashboard\_link](#input\_dashboard\_link) | Dashboard link to include in message | `string` | `null` | no |
| <a name="input_env"></a> [env](#input\_env) | Environment the monitored resource is in (leave blank to omit tag) | `string` | n/a | yes |
| <a name="input_evaluation_delay"></a> [evaluation\_delay](#input\_evaluation\_delay) | Monitor evaluation delay (see [https://docs.datadoghq.com/monitors/configuration/?tab=thresholdalert#set-alert-conditions](Datadog Docs)) | `number` | `900` | no |
| <a name="input_monitor_exclude_tags"></a> [monitor\_exclude\_tags](#input\_monitor\_exclude\_tags) | Tags to be excluded in the monitoring query. Specify in key:value format | `list(string)` | `[]` | no |
| <a name="input_monitor_include_tags"></a> [monitor\_include\_tags](#input\_monitor\_include\_tags) | Tags to be included in the monitoring query. Specify in key:value format | `list(string)` | `[]` | no |
| <a name="input_new_group_delay"></a> [new\_group\_delay](#input\_new\_group\_delay) | Delay in seconds before generating alerts for a new resource | `number` | `300` | no |
| <a name="input_notify_alert_override"></a> [notify\_alert\_override](#input\_notify\_alert\_override) | List of notifications for alerts in critical threshold (uses `notify_default` otherwise) | `list(string)` | `[]` | no |
| <a name="input_notify_default"></a> [notify\_default](#input\_notify\_default) | List of alert notifications (can be overridden based on alert type) | `list(string)` | n/a | yes |
| <a name="input_notify_no_data"></a> [notify\_no\_data](#input\_notify\_no\_data) | Alert if no matching data is found | `bool` | `false` | no |
| <a name="input_notify_nodata_override"></a> [notify\_nodata\_override](#input\_notify\_nodata\_override) | List of notifications for no data (uses `notify_default` otherwise) | `list(string)` | `[]` | no |
| <a name="input_notify_recovery_override"></a> [notify\_recovery\_override](#input\_notify\_recovery\_override) | List of notifications for alert recovery (uses `notify_default` otherwise) | `list(string)` | `[]` | no |
| <a name="input_notify_warn_override"></a> [notify\_warn\_override](#input\_notify\_warn\_override) | List of notifications for alerts in warning threshold (uses `notify_default` otherwise) | `list(string)` | `[]` | no |
| <a name="input_renotify_interval"></a> [renotify\_interval](#input\_renotify\_interval) | Interval in minutes to re-send notifications about an alert | `number` | `0` | no |
| <a name="input_runbook_link"></a> [runbook\_link](#input\_runbook\_link) | Runbook link to include in message | `string` | `null` | no |
| <a name="input_service"></a> [service](#input\_service) | Service associated with the monitored resource (leave blank to omit tag) | `string` | `null` | no |
| <a name="input_team"></a> [team](#input\_team) | Team supporting the monitored resource (leave blank to omit tag) | `string` | `null` | no |
| <a name="input_timeout_h"></a> [timeout\_h](#input\_timeout\_h) | Auto-resolve alert in specified hours if condition no longer matches | `number` | `0` | no |
| <a name="input_title_prefix"></a> [title\_prefix](#input\_title\_prefix) | Prefix all alerts with specified value in brackets | `string` | `null` | no |
| <a name="input_title_suffix"></a> [title\_suffix](#input\_title\_suffix) | Suffix all alerts with specified value in parenthesis | `string` | `null` | no |
| <a name="input_warn_priority"></a> [warn\_priority](#input\_warn\_priority) | Priority for alerts with no data (P1-P5, uses monitor defaults if not specified) | `string` | `null` | no |

## Outputs

No outputs.
<!-- END_TF_DOCS -->
1 change: 1 addition & 0 deletions synthetics/browser/common.tf
74 changes: 74 additions & 0 deletions synthetics/browser/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
locals {
# these must be defined but do not need to be overridden
monitor_alert_default_priority = null
monitor_warn_default_priority = null
monitor_nodata_default_priority = null

title_prefix = "${var.title_prefix == null ? "" : "[${var.title_prefix}]"}[${var.env}] "
title_suffix = var.title_suffix == null ? "" : " (${var.title_suffix})"
}

resource "datadog_synthetics_test" "browser" {
count = var.browser_synthetic_enabled ? 1 : 0

name = join("", [local.title_prefix, "Browser Test", local.title_suffix])
type = "browser"
status = "live"
message = local.synthetic_alert_base_message
device_ids = var.browser_synthetic_device_ids
locations = var.browser_synthetic_locations
tags = concat(local.common_tags, var.base_tags, var.additional_tags)

request_definition {
method = "GET"
url = var.browser_synthetic_request_url
}

dynamic "browser_step" {
for_each = var.browser_synthetic_steps
content {
name = browser_step.value.name
type = browser_step.value.type
params {
attribute = lookup(browser_step.value.params, "attribute", null)
check = lookup(browser_step.value.params, "check", null)
click_type = lookup(browser_step.value.params, "click_type", null)
code = lookup(browser_step.value.params, "code", null)
delay = lookup(browser_step.value.params, "delay", null)
element = lookup(browser_step.value.params, "element", null)
dynamic "element_user_locator" {
for_each = browser_step.value.params.element_user_locator != null ? browser_step.value.params.element_user_locator : {}
content {
value {
value = lookup(element_user_locator.value, "value", null)
type = lookup(element_user_locator.value, "type", null)
}
fail_test_on_cannot_locate = lookup(element_user_locator.value, "fail_test_on_cannot_locate", null)
}
}
email = lookup(browser_step.value.params, "email", null)
file = lookup(browser_step.value.params, "file", null)
files = lookup(browser_step.value.params, "files", null)
modifiers = lookup(browser_step.value.params, "modifiers", null)
playing_tab_id = lookup(browser_step.value.params, "playing_tab_id", null)
request = lookup(browser_step.value.params, "request", null)
subtest_public_id = lookup(browser_step.value.params, "subtest_public_id", null)
value = lookup(browser_step.value.params, "value", null)
dynamic "variable" {
for_each = browser_step.value.params.variable != null ? browser_step.value.params.variable : {}
content {
example = lookup(variable.value, "example", null)
name = lookup(variable.value, "name", null)
}
}
with_click = lookup(browser_step.value.params, "with_click", null)
x = lookup(browser_step.value.params, "x", null)
y = lookup(browser_step.value.params, "y", null)
}
}
}

options_list {
tick_every = var.browser_synthetic_tick_every
}
}
75 changes: 75 additions & 0 deletions synthetics/browser/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
########################################
# Global variables
########################################
variable "additional_tags" {
default = []
description = "Additional tags (key:value format) to add to this type of check (combined with `local.tags` and `var.base_tags`)"
type = list(string)
}

variable "base_tags" {
default = ["resource:apigateway"]
description = "Base tags (key:value format) to add to this type of check (combined with `local.tags` and `var.additional_tags`, generally you should not change this)"
type = list(string)
}

########################################
# Browser Synthetic Test variables
########################################
variable "browser_synthetic_enabled" {
description = "Flag to enable Browser Synthetic Test."
type = bool
default = true
}

variable "browser_synthetic_device_ids" {
description = "List with the different device IDs used to run the test. Valid values are laptop_large, tablet, mobile_small, chrome.laptop_large, chrome.tablet, chrome.mobile_small, firefox.laptop_large, firefox.tablet, firefox.mobile_small, edge.laptop_large, edge.tablet, edge.mobile_small."
type = list(string)
default = ["laptop_large"]
}

variable "browser_synthetic_locations" {
description = "An array of datadog locations used to run Browser Synthetic Test."
type = list(string)
default = ["aws:us-east-1"]
}

variable "browser_synthetic_request_url" {
description = "URL to send Browser Synthetic Test requests to."
type = string
}

variable "browser_synthetic_steps" {
description = "Steps for the Browser Synthetic Test to take."
type = list(object({
name = string
type = string
params = object({
attribute = optional(string)
check = optional(string)
click_type = optional(string)
code = optional(string)
delay = optional(number)
element = optional(string)
element_user_locator = optional(map(string))
email = optional(string)
file = optional(string)
files = optional(string)
modifiers = optional(list(string))
playing_tab_id = optional(string)
request = optional(string)
subtest_public_id = optional(string)
value = optional(string)
variable = optional(map(string))
with_click = optional(bool)
x = optional(number)
y = optional(number)
})
}))
}

variable "browser_synthetic_tick_every" {
description = "How often Browser Synthetic Test should run in seconds."
type = number
default = 900
}
1 change: 1 addition & 0 deletions synthetics/browser/versions.tf
44 changes: 44 additions & 0 deletions synthetics/ssl/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e342e79

Please sign in to comment.