Skip to content

Commit 57c6212

Browse files
authored
[datadog-synthetics] Accept Datadog API output as input (cloudposse/terraform-aws-components#885)
1 parent aaea91a commit 57c6212

File tree

6 files changed

+113
-69
lines changed

6 files changed

+113
-69
lines changed

src/CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
## Changes approximately v1.329.0
2+
3+
### API Schema accepted
4+
5+
Test can now be defined using the Datadog API schema, meaning that the test definition
6+
returned by
7+
- `https://api.datadoghq.com/api/v1/synthetics/tests/api/{public_id}`
8+
- `https://api.datadoghq.com/api/v1/synthetics/tests/browser/{public_id}`
9+
10+
can be directly used a map value (you still need to supply a key, though).
11+
12+
You can mix tests using the API schema with tests using the old Terraform schema.
13+
You could probably get away with mixing them in the same test, but it is not recommended.
14+
15+
### Default locations
16+
17+
Previously, the default locations for Synthetics tests were "all" public locations.
18+
Now the default is no locations, in favor of locations being specified in each test configuration,
19+
which is more flexible. Also, since the tests are expensive, it is better to err on the side of
20+
too few test locations than too many.

src/README.md

Lines changed: 48 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -39,41 +39,56 @@ components:
3939
4040
Below are examples of Datadog browser and API synthetic tests.
4141
42-
The synthetic tests are defined in YAML using the [Datadog Terraform provider](https://registry.terraform.io/providers/DataDog/datadog/latest/docs/resources/synthetics_test) schema.
42+
The synthetic tests are defined in YAML using either the [Datadog Terraform provider](https://registry.terraform.io/providers/DataDog/datadog/latest/docs/resources/synthetics_test) schema
43+
or the [Datadog Synthetics API](https://docs.datadoghq.com/api/latest/synthetics) schema.
44+
See the `terraform-datadog-platform` Terraform module [README](https://github.com/cloudposse/terraform-datadog-platform/blob/main/modules/synthetics/README.md) for more details.
45+
We recommend using the API schema so you can more create and edit tests using the Datadog
46+
web API and then import them into this module by downloading the test using
47+
the Datadog REST API. (See the Datadog API documentation for the appropriate
48+
`curl` commands to use.)
4349

4450
```yaml
51+
# API schema
4552
my-browser-test:
46-
name: "Browser Test"
47-
message: "Browser Test Failed"
53+
name: My Browser Test
54+
status: live
4855
type: browser
49-
subtype: http
50-
device_ids:
51-
- "laptop_large"
52-
tags:
53-
- "managed-by:Terraform"
54-
status: "live"
55-
request_definition:
56-
url: "CHANGEME"
57-
method: GET
58-
request_headers:
59-
Accept-Charset: "utf-8, iso-8859-1;q=0.5"
60-
Accept: "text/html"
61-
options_list:
62-
tick_every: 1800
63-
no_screenshot: false
64-
follow_redirects: false
56+
config:
57+
request:
58+
method: GET
59+
headers: {}
60+
url: https://example.com/login
61+
setCookie: |-
62+
DatadogTest=true
63+
message: "My Browser Test Failed"
64+
options:
65+
device_ids:
66+
- chrome.laptop_large
67+
- edge.tablet
68+
- firefox.mobile_small
69+
ignoreServerCertificateError: false
70+
disableCors: false
71+
disableCsp: false
72+
noScreenshot: false
73+
tick_every: 86400
74+
min_failure_duration: 0
75+
min_location_failed: 1
6576
retry:
66-
count: 2
67-
interval: 10
77+
count: 0
78+
interval: 300
6879
monitor_options:
69-
renotify_interval: 300
70-
browser_step:
71-
- name: "Check current URL"
72-
type: assertCurrentUrl
73-
params:
74-
check: contains
75-
value: "CHANGEME"
76-
80+
renotify_interval: 0
81+
ci:
82+
executionRule: non_blocking
83+
rumSettings:
84+
isEnabled: false
85+
enableProfiling: false
86+
enableSecurityTesting: false
87+
locations:
88+
- aws:us-east-1
89+
- aws:us-west-2
90+
91+
# Terraform schema
7792
my-api-test:
7893
name: "API Test"
7994
message: "API Test Failed"
@@ -145,7 +160,7 @@ No providers.
145160
| Name | Source | Version |
146161
|------|--------|---------|
147162
| <a name="module_datadog_configuration"></a> [datadog\_configuration](#module\_datadog\_configuration) | ../datadog-configuration/modules/datadog_keys | n/a |
148-
| <a name="module_datadog_synthetics"></a> [datadog\_synthetics](#module\_datadog\_synthetics) | cloudposse/platform/datadog//modules/synthetics | 1.0.1 |
163+
| <a name="module_datadog_synthetics"></a> [datadog\_synthetics](#module\_datadog\_synthetics) | cloudposse/platform/datadog//modules/synthetics | 1.3.0 |
149164
| <a name="module_datadog_synthetics_merge"></a> [datadog\_synthetics\_merge](#module\_datadog\_synthetics\_merge) | cloudposse/config/yaml//modules/deepmerge | 1.0.2 |
150165
| <a name="module_datadog_synthetics_private_location"></a> [datadog\_synthetics\_private\_location](#module\_datadog\_synthetics\_private\_location) | cloudposse/stack-config/yaml//modules/remote-state | 1.5.0 |
151166
| <a name="module_datadog_synthetics_yaml_config"></a> [datadog\_synthetics\_yaml\_config](#module\_datadog\_synthetics\_yaml\_config) | cloudposse/config/yaml | 1.0.2 |
@@ -164,7 +179,7 @@ No resources.
164179
| <a name="input_alert_tags"></a> [alert\_tags](#input\_alert\_tags) | List of alert tags to add to all alert messages, e.g. `["@opsgenie"]` or `["@devops", "@opsgenie"]` | `list(string)` | `null` | no |
165180
| <a name="input_alert_tags_separator"></a> [alert\_tags\_separator](#input\_alert\_tags\_separator) | Separator for the alert tags. All strings from the `alert_tags` variable will be joined into one string using the separator and then added to the alert message | `string` | `"\n"` | no |
166181
| <a name="input_attributes"></a> [attributes](#input\_attributes) | ID element. Additional attributes (e.g. `workers` or `cluster`) to add to `id`,<br>in the order they appear in the list. New attributes are appended to the<br>end of the list. The elements of the list are joined by the `delimiter`<br>and treated as a single ID element. | `list(string)` | `[]` | no |
167-
| <a name="input_config_parameters"></a> [config\_parameters](#input\_config\_parameters) | Map of parameters to Datadog Synthetic configurations | `map(any)` | `{}` | no |
182+
| <a name="input_config_parameters"></a> [config\_parameters](#input\_config\_parameters) | Map of parameter values to interpolate into Datadog Synthetic configurations | `map(any)` | `{}` | no |
168183
| <a name="input_context"></a> [context](#input\_context) | Single object for setting entire context at once.<br>See description of individual variables for details.<br>Leave string and numeric variables as `null` to use default value.<br>Individual variable settings (non-null) override settings in context object,<br>except for attributes, tags, and additional\_tag\_map, which are merged. | `any` | <pre>{<br> "additional_tag_map": {},<br> "attributes": [],<br> "delimiter": null,<br> "descriptor_formats": {},<br> "enabled": true,<br> "environment": null,<br> "id_length_limit": null,<br> "label_key_case": null,<br> "label_order": [],<br> "label_value_case": null,<br> "labels_as_tags": [<br> "unset"<br> ],<br> "name": null,<br> "namespace": null,<br> "regex_replace_chars": null,<br> "stage": null,<br> "tags": {},<br> "tenant": null<br>}</pre> | no |
169184
| <a name="input_context_tags"></a> [context\_tags](#input\_context\_tags) | List of context tags to add to each synthetic check | `set(string)` | <pre>[<br> "namespace",<br> "tenant",<br> "environment",<br> "stage"<br>]</pre> | no |
170185
| <a name="input_context_tags_enabled"></a> [context\_tags\_enabled](#input\_context\_tags\_enabled) | Whether to add context tags to add to each synthetic check | `bool` | `true` | no |
@@ -178,7 +193,7 @@ No resources.
178193
| <a name="input_label_order"></a> [label\_order](#input\_label\_order) | The order in which the labels (ID elements) appear in the `id`.<br>Defaults to ["namespace", "environment", "stage", "name", "attributes"].<br>You can omit any of the 6 labels ("tenant" is the 6th), but at least one must be present. | `list(string)` | `null` | no |
179194
| <a name="input_label_value_case"></a> [label\_value\_case](#input\_label\_value\_case) | Controls the letter case of ID elements (labels) as included in `id`,<br>set as tag values, and output by this module individually.<br>Does not affect values of tags passed in via the `tags` input.<br>Possible values: `lower`, `title`, `upper` and `none` (no transformation).<br>Set this to `title` and set `delimiter` to `""` to yield Pascal Case IDs.<br>Default value: `lower`. | `string` | `null` | no |
180195
| <a name="input_labels_as_tags"></a> [labels\_as\_tags](#input\_labels\_as\_tags) | Set of labels (ID elements) to include as tags in the `tags` output.<br>Default is to include all labels.<br>Tags with empty values will not be included in the `tags` output.<br>Set to `[]` to suppress all generated tags.<br>**Notes:**<br> The value of the `name` tag, if included, will be the `id`, not the `name`.<br> Unlike other `null-label` inputs, the initial setting of `labels_as_tags` cannot be<br> changed in later chained modules. Attempts to change it will be silently ignored. | `set(string)` | <pre>[<br> "default"<br>]</pre> | no |
181-
| <a name="input_locations"></a> [locations](#input\_locations) | Array of locations used to run synthetic tests | `list(string)` | <pre>[<br> "all"<br>]</pre> | no |
196+
| <a name="input_locations"></a> [locations](#input\_locations) | Array of locations used to run synthetic tests | `list(string)` | `[]` | no |
182197
| <a name="input_name"></a> [name](#input\_name) | ID element. Usually the component or solution name, e.g. 'app' or 'jenkins'.<br>This is the only ID element not also included as a `tag`.<br>The "name" tag is set to the full `id` string. There is no tag with the value of the `name` input. | `string` | `null` | no |
183198
| <a name="input_namespace"></a> [namespace](#input\_namespace) | ID element. Usually an abbreviation of your organization name, e.g. 'eg' or 'cp', to help ensure generated IDs are globally unique | `string` | `null` | no |
184199
| <a name="input_private_location_test_enabled"></a> [private\_location\_test\_enabled](#input\_private\_location\_test\_enabled) | Use private locations or the public locations provided by datadog | `bool` | `false` | no |
@@ -195,9 +210,9 @@ No resources.
195210
| Name | Description |
196211
|------|-------------|
197212
| <a name="output_datadog_synthetics_test_ids"></a> [datadog\_synthetics\_test\_ids](#output\_datadog\_synthetics\_test\_ids) | IDs of the created Datadog synthetic tests |
213+
| <a name="output_datadog_synthetics_test_maps"></a> [datadog\_synthetics\_test\_maps](#output\_datadog\_synthetics\_test\_maps) | Map (name: id) of the created Datadog synthetic tests |
198214
| <a name="output_datadog_synthetics_test_monitor_ids"></a> [datadog\_synthetics\_test\_monitor\_ids](#output\_datadog\_synthetics\_test\_monitor\_ids) | IDs of the monitors associated with the Datadog synthetics tests |
199215
| <a name="output_datadog_synthetics_test_names"></a> [datadog\_synthetics\_test\_names](#output\_datadog\_synthetics\_test\_names) | Names of the created Datadog synthetic tests |
200-
| <a name="output_datadog_synthetics_tests"></a> [datadog\_synthetics\_tests](#output\_datadog\_synthetics\_tests) | The synthetic tests created in Datadog |
201216
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
202217

203218
## References
Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,38 @@
11
my-browser-test:
2-
name: "Browser Test"
3-
message: "Browser Test Failed"
2+
name: My Browser Test
3+
status: live
44
type: browser
5-
subtype: http
6-
device_ids:
7-
- "laptop_large"
8-
tags:
9-
- "managed-by:Terraform"
10-
status: "live"
11-
request_definition:
12-
url: "CHANGEME"
13-
method: GET
14-
request_headers:
15-
Accept-Charset: "utf-8, iso-8859-1;q=0.5"
16-
Accept: "text/html"
17-
options_list:
18-
tick_every: 1800
19-
no_screenshot: false
20-
follow_redirects: false
5+
config:
6+
request:
7+
method: GET
8+
headers: {}
9+
url: https://example.com/login
10+
setCookie: |-
11+
DatadogTest=true
12+
message: "My Browser Test Failed"
13+
options:
14+
device_ids:
15+
- chrome.laptop_large
16+
- edge.tablet
17+
- firefox.mobile_small
18+
ignoreServerCertificateError: false
19+
disableCors: false
20+
disableCsp: false
21+
noScreenshot: false
22+
tick_every: 86400
23+
min_failure_duration: 0
24+
min_location_failed: 1
2125
retry:
22-
count: 2
23-
interval: 10
26+
count: 0
27+
interval: 300
2428
monitor_options:
25-
renotify_interval: 300
26-
browser_step:
27-
- name: "Check current URL"
28-
type: assertCurrentUrl
29-
params:
30-
check: contains
31-
value: "CHANGEME"
29+
renotify_interval: 0
30+
ci:
31+
executionRule: non_blocking
32+
rumSettings:
33+
isEnabled: false
34+
enableProfiling: false
35+
enableSecurityTesting: false
36+
locations:
37+
- aws:us-east-1
38+
- aws:us-west-2

src/main.tf

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@ module "datadog_synthetics_merge" {
5050

5151
module "datadog_synthetics" {
5252
source = "cloudposse/platform/datadog//modules/synthetics"
53-
version = "1.0.1"
53+
version = "1.3.0"
5454

55-
datadog_synthetics = local.synthetics_merged
55+
# Disable default tags because we manage them ourselves in this module, because we want to make them lowercase.
56+
default_tags_enabled = false
57+
datadog_synthetics = local.synthetics_merged
5658

5759
locations = distinct(compact(concat(
5860
var.locations,

src/outputs.tf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
output "datadog_synthetics_tests" {
2-
value = module.datadog_synthetics.datadog_synthetic_tests
3-
description = "The synthetic tests created in Datadog"
4-
}
5-
61
output "datadog_synthetics_test_names" {
72
value = module.datadog_synthetics.datadog_synthetics_test_names
83
description = "Names of the created Datadog synthetic tests"
@@ -17,3 +12,8 @@ output "datadog_synthetics_test_monitor_ids" {
1712
value = module.datadog_synthetics.datadog_synthetics_test_monitor_ids
1813
description = "IDs of the monitors associated with the Datadog synthetics tests"
1914
}
15+
16+
output "datadog_synthetics_test_maps" {
17+
value = { for v in module.datadog_synthetics.datadog_synthetic_tests : v.name => v.id }
18+
description = "Map (name: id) of the created Datadog synthetic tests"
19+
}

src/variables.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ variable "context_tags" {
3434

3535
variable "config_parameters" {
3636
type = map(any)
37-
description = "Map of parameters to Datadog Synthetic configurations"
37+
description = "Map of parameter values to interpolate into Datadog Synthetic configurations"
3838
default = {}
3939
}
4040

@@ -47,7 +47,7 @@ variable "datadog_synthetics_globals" {
4747
variable "locations" {
4848
type = list(string)
4949
description = "Array of locations used to run synthetic tests"
50-
default = ["all"]
50+
default = []
5151
}
5252

5353
variable "private_location_test_enabled" {

0 commit comments

Comments
 (0)