-
Notifications
You must be signed in to change notification settings - Fork 392
/
Copy pathresource_datadog_synthetics_test_.go
5375 lines (4837 loc) · 189 KB
/
resource_datadog_synthetics_test_.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// For more info about writing custom provider: https://www.terraform.io/docs/extend/writing-custom-providers.html
package datadog
import (
"bytes"
"compress/zlib"
"context"
b64 "encoding/base64"
"encoding/json"
"fmt"
"io"
"log"
_nethttp "net/http"
"regexp"
"strconv"
"strings"
"github.com/terraform-providers/terraform-provider-datadog/datadog/internal/utils"
"github.com/terraform-providers/terraform-provider-datadog/datadog/internal/validators"
"github.com/DataDog/datadog-api-client-go/v2/api/datadogV1"
"github.com/hashicorp/go-cty/cty"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)
/*
* Resource
*/
func resourceDatadogSyntheticsTest() *schema.Resource {
return &schema.Resource{
Description: "Provides a Datadog synthetics test resource. This can be used to create and manage Datadog synthetics test.",
CreateContext: resourceDatadogSyntheticsTestCreate,
ReadContext: resourceDatadogSyntheticsTestRead,
UpdateContext: resourceDatadogSyntheticsTestUpdate,
DeleteContext: resourceDatadogSyntheticsTestDelete,
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},
SchemaFunc: func() map[string]*schema.Schema {
return map[string]*schema.Schema{
"type": {
Description: "Synthetics test type.",
Type: schema.TypeString,
Required: true,
ValidateDiagFunc: validators.ValidateEnumValue(datadogV1.NewSyntheticsTestDetailsTypeFromValue),
},
"subtype": {
Description: "The subtype of the Synthetic API test. Defaults to `http`.",
Type: schema.TypeString,
Optional: true,
DiffSuppressFunc: func(key, old, new string, d *schema.ResourceData) bool {
if d.Get("type") == "api" && old == "http" && new == "" {
// defaults to http if type is api for retro-compatibility
return true
}
return old == new
},
ValidateDiagFunc: validators.ValidateEnumValue(datadogV1.NewSyntheticsTestDetailsSubTypeFromValue),
},
"request_definition": {
Description: "Required if `type = \"api\"`. The synthetics test request.",
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Elem: syntheticsTestRequest(),
},
"request_headers": syntheticsTestRequestHeaders(),
"request_query": syntheticsTestRequestQuery(),
"request_basicauth": syntheticsTestRequestBasicAuth(),
"request_proxy": syntheticsTestRequestProxy(),
"request_client_certificate": syntheticsTestRequestClientCertificate(),
"request_metadata": syntheticsTestRequestMetadata(),
"request_file": syntheticsTestRequestFile(),
"assertion": syntheticsAPIAssertion(),
"browser_variable": syntheticsBrowserVariable(),
"config_variable": syntheticsConfigVariable(),
"config_initial_application_arguments": {
Description: "Initial application arguments for the mobile test.",
Type: schema.TypeMap,
Optional: true,
},
"variables_from_script": {
Description: "Variables defined from JavaScript code for API HTTP tests.",
Type: schema.TypeString,
Optional: true,
},
"device_ids": {
Description: "Required if `type = \"browser\"`. Array with the different device IDs used to run the test.",
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateDiagFunc: validators.ValidateNonEmptyStrings,
},
},
"locations": {
Description: "Array of locations used to run the test. Refer to [the Datadog Synthetics location data source](https://registry.terraform.io/providers/DataDog/datadog/latest/docs/data-sources/synthetics_locations) to retrieve the list of locations.",
Type: schema.TypeSet,
Required: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"options_list": syntheticsTestOptionsList(),
"mobile_options_list": syntheticsMobileTestOptionsList(),
"name": {
Description: "Name of Datadog synthetics test.",
Type: schema.TypeString,
Required: true,
},
"message": {
Description: "A message to include with notifications for this synthetics test. Email notifications can be sent to specific users by using the same `@username` notation as events.",
Type: schema.TypeString,
Optional: true,
Default: "",
},
"tags": {
Description: "A list of tags to associate with your synthetics test. This can help you categorize and filter tests in the manage synthetics page of the UI. Default is an empty list (`[]`).",
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateDiagFunc: validators.ValidateNonEmptyStrings,
},
},
"status": {
Description: "Define whether you want to start (`live`) or pause (`paused`) a Synthetic test.",
Type: schema.TypeString,
Required: true,
ValidateDiagFunc: validators.ValidateEnumValue(datadogV1.NewSyntheticsTestPauseStatusFromValue),
},
"monitor_id": {
Description: "ID of the monitor associated with the Datadog synthetics test.",
Type: schema.TypeInt,
Computed: true,
},
"browser_step": syntheticsTestBrowserStep(),
"api_step": syntheticsTestAPIStep(),
"mobile_step": syntheticsTestMobileStep(),
"set_cookie": {
Description: "Cookies to be used for a browser test request, using the [Set-Cookie](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie) syntax.",
Type: schema.TypeString,
Optional: true,
},
"force_delete_dependencies": {
Description: "A boolean indicating whether this synthetics test can be deleted even if it's referenced by other resources (for example, SLOs and composite monitors).",
Type: schema.TypeBool,
Optional: true,
},
}
},
}
}
/*
* Schemas
*/
func syntheticsTestRequest() *schema.Resource {
return &schema.Resource{
Schema: map[string]*schema.Schema{
"method": {
Description: "Either the HTTP method/verb to use or a gRPC method available on the service set in the `service` field. Required if `subtype` is `HTTP` or if `subtype` is `grpc` and `callType` is `unary`.",
Type: schema.TypeString,
Optional: true,
},
"url": {
Description: "The URL to send the request to.",
Type: schema.TypeString,
Optional: true,
},
"body": {
Description: "The request body.",
Type: schema.TypeString,
Optional: true,
},
"body_type": {
Description: "Type of the request body.",
Type: schema.TypeString,
Optional: true,
ValidateDiagFunc: validators.ValidateEnumValue(datadogV1.NewSyntheticsTestRequestBodyTypeFromValue),
},
"timeout": {
Description: "Timeout in seconds for the test.",
Type: schema.TypeInt,
Optional: true,
},
"host": {
Description: "Host name to perform the test with.",
Type: schema.TypeString,
Optional: true,
},
"port": {
Description: "Port to use when performing the test.",
Type: schema.TypeString,
Optional: true,
},
"dns_server": {
Description: "DNS server to use for DNS tests (`subtype = \"dns\"`).",
Type: schema.TypeString,
Optional: true,
},
"dns_server_port": {
Description: "DNS server port to use for DNS tests.",
Type: schema.TypeString,
Optional: true,
},
"no_saving_response_body": {
Description: "Determines whether or not to save the response body.",
Type: schema.TypeBool,
Optional: true,
},
"number_of_packets": {
Description: "Number of pings to use per test for ICMP tests (`subtype = \"icmp\"`) between 0 and 10.",
Type: schema.TypeInt,
Optional: true,
ValidateFunc: validation.IntBetween(0, 10),
},
"should_track_hops": {
Description: "This will turn on a traceroute probe to discover all gateways along the path to the host destination. For ICMP tests (`subtype = \"icmp\"`).",
Type: schema.TypeBool,
Optional: true,
},
"servername": {
Description: "For SSL tests, it specifies on which server you want to initiate the TLS handshake, allowing the server to present one of multiple possible certificates on the same IP address and TCP port number.",
Type: schema.TypeString,
Optional: true,
},
"message": {
Description: "For UDP and websocket tests, message to send with the request.",
Type: schema.TypeString,
Optional: true,
},
"call_type": {
Description: "The type of gRPC call to perform.",
Type: schema.TypeString,
Optional: true,
ValidateDiagFunc: validators.ValidateEnumValue(datadogV1.NewSyntheticsTestCallTypeFromValue),
},
"service": {
Description: "The gRPC service on which you want to perform the gRPC call.",
Type: schema.TypeString,
Optional: true,
},
"certificate_domains": {
Description: "By default, the client certificate is applied on the domain of the starting URL for browser tests. If you want your client certificate to be applied on other domains instead, add them in `certificate_domains`.",
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"persist_cookies": {
Description: "Persist cookies across redirects.",
Type: schema.TypeBool,
Optional: true,
},
"proto_json_descriptor": {
Description: "A protobuf JSON descriptor.",
Type: schema.TypeString,
Optional: true,
Deprecated: "Use `plain_proto_file` instead.",
},
"plain_proto_file": {
Description: "The content of a proto file as a string.",
Type: schema.TypeString,
Optional: true,
},
"http_version": {
Description: "HTTP version to use for an HTTP request in an API test or step.",
Deprecated: "Use `http_version` in the `options_list` field instead.",
Type: schema.TypeString,
Optional: true,
},
},
}
}
func syntheticsTestRequestHeaders() *schema.Schema {
return &schema.Schema{
Description: "Header name and value map.",
Type: schema.TypeMap,
Optional: true,
ValidateFunc: validators.ValidateHttpRequestHeader,
}
}
func syntheticsTestRequestQuery() *schema.Schema {
return &schema.Schema{
Description: "Query arguments name and value map.",
Type: schema.TypeMap,
Optional: true,
}
}
func syntheticsTestRequestBasicAuth() *schema.Schema {
return &schema.Schema{
Description: "The HTTP basic authentication credentials. Exactly one nested block is allowed with the structure below.",
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"type": {
Description: "Type of basic authentication to use when performing the test.",
Type: schema.TypeString,
Optional: true,
Default: "web",
ValidateFunc: validation.StringInSlice([]string{"web", "sigv4", "ntlm", "oauth-client", "oauth-rop", "digest"}, false),
},
"username": {
Description: "Username for authentication.",
Type: schema.TypeString,
Optional: true,
},
"password": {
Description: "Password for authentication.",
Type: schema.TypeString,
Optional: true,
Sensitive: true,
},
"access_key": {
Type: schema.TypeString,
Description: "Access key for `SIGV4` authentication.",
Optional: true,
Sensitive: true,
},
"secret_key": {
Type: schema.TypeString,
Description: "Secret key for `SIGV4` authentication.",
Optional: true,
Sensitive: true,
},
"region": {
Type: schema.TypeString,
Description: "Region for `SIGV4` authentication.",
Optional: true,
},
"service_name": {
Type: schema.TypeString,
Description: "Service name for `SIGV4` authentication.",
Optional: true,
},
"session_token": {
Type: schema.TypeString,
Description: "Session token for `SIGV4` authentication.",
Optional: true,
},
"domain": {
Type: schema.TypeString,
Description: "Domain for `ntlm` authentication.",
Optional: true,
},
"workstation": {
Type: schema.TypeString,
Description: "Workstation for `ntlm` authentication.",
Optional: true,
},
"access_token_url": {
Type: schema.TypeString,
Description: "Access token url for `oauth-client` or `oauth-rop` authentication.",
Optional: true,
},
"audience": {
Type: schema.TypeString,
Description: "Audience for `oauth-client` or `oauth-rop` authentication.",
Optional: true,
Default: "",
},
"resource": {
Type: schema.TypeString,
Description: "Resource for `oauth-client` or `oauth-rop` authentication.",
Optional: true,
Default: "",
},
"scope": {
Type: schema.TypeString,
Description: "Scope for `oauth-client` or `oauth-rop` authentication.",
Optional: true,
Default: "",
},
"token_api_authentication": {
Type: schema.TypeString,
Description: "Token API Authentication for `oauth-client` or `oauth-rop` authentication.",
Optional: true,
ValidateDiagFunc: validators.ValidateEnumValue(datadogV1.NewSyntheticsBasicAuthOauthTokenApiAuthenticationFromValue),
},
"client_id": {
Type: schema.TypeString,
Description: "Client ID for `oauth-client` or `oauth-rop` authentication.",
Optional: true,
},
"client_secret": {
Type: schema.TypeString,
Description: "Client secret for `oauth-client` or `oauth-rop` authentication.",
Optional: true,
Sensitive: true,
},
},
},
}
}
func syntheticsTestRequestProxy() *schema.Schema {
return &schema.Schema{
Description: "The proxy to perform the test.",
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"url": {
Type: schema.TypeString,
Description: "URL of the proxy to perform the test.",
Required: true,
},
"headers": syntheticsTestRequestHeaders(),
},
},
}
}
func syntheticsTestRequestClientCertificate() *schema.Schema {
return &schema.Schema{
Description: "Client certificate to use when performing the test request. Exactly one nested block is allowed with the structure below.",
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"cert": syntheticsTestRequestClientCertificateItem(),
"key": syntheticsTestRequestClientCertificateItem(),
},
},
}
}
func syntheticsTestRequestClientCertificateItem() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
MaxItems: 1,
Required: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"content": {
Description: "Content of the certificate.",
Type: schema.TypeString,
Required: true,
Sensitive: true,
StateFunc: func(val interface{}) string {
return utils.ConvertToSha256(val.(string))
},
},
"filename": {
Description: "File name for the certificate.",
Type: schema.TypeString,
Optional: true,
Default: "Provided in Terraform config",
},
},
},
}
}
func syntheticsTestRequestMetadata() *schema.Schema {
return &schema.Schema{
Description: "Metadata to include when performing the gRPC request.",
Type: schema.TypeMap,
Optional: true,
}
}
func syntheticsAPIAssertion() *schema.Schema {
return &schema.Schema{
Description: "Assertions used for the test. Multiple `assertion` blocks are allowed with the structure below.",
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"type": {
Description: "Type of assertion. **Note** Only some combinations of `type` and `operator` are valid (please refer to [Datadog documentation](https://docs.datadoghq.com/api/latest/synthetics/#create-a-test)).",
Type: schema.TypeString,
ValidateDiagFunc: validators.ValidateEnumValue(datadogV1.NewSyntheticsAssertionTypeFromValue, datadogV1.NewSyntheticsAssertionBodyHashTypeFromValue, datadogV1.NewSyntheticsAssertionJavascriptTypeFromValue),
Required: true,
},
"operator": {
Description: "Assertion operator. **Note** Only some combinations of `type` and `operator` are valid (please refer to [Datadog documentation](https://docs.datadoghq.com/api/latest/synthetics/#create-a-test)).",
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateSyntheticsAssertionOperator,
},
"property": {
Description: "If assertion type is `header`, this is the header name.",
Type: schema.TypeString,
Optional: true,
},
"target": {
Description: "Expected value. Depends on the assertion type, refer to [Datadog documentation](https://docs.datadoghq.com/api/latest/synthetics/#create-a-test) for details.",
Type: schema.TypeString,
Optional: true,
},
"code": {
Description: "If assertion type is `javascript`, this is the JavaScript code that performs the assertions.",
Type: schema.TypeString,
Optional: true,
},
"targetjsonschema": {
Description: "Expected structure if `operator` is `validatesJSONSchema`. Exactly one nested block is allowed with the structure below.",
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"jsonschema": {
Description: "The JSON Schema to validate the body against.",
Type: schema.TypeString,
Required: true,
},
"metaschema": {
Description: "The meta schema to use for the JSON Schema.",
Type: schema.TypeString,
Optional: true,
Default: "draft-07",
},
},
},
},
"targetjsonpath": {
Description: "Expected structure if `operator` is `validatesJSONPath`. Exactly one nested block is allowed with the structure below.",
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"elementsoperator": {
Description: "The element from the list of results to assert on. Select from `firstElementMatches` (the first element in the list), `everyElementMatches` (every element in the list), `atLeastOneElementMatches` (at least one element in the list), or `serializationMatches` (the serialized value of the list).",
Type: schema.TypeString,
Optional: true,
Default: "firstElementMatches",
},
"operator": {
Description: "The specific operator to use on the path.",
Type: schema.TypeString,
Required: true,
},
"jsonpath": {
Description: "The JSON path to assert.",
Type: schema.TypeString,
Required: true,
},
"targetvalue": {
Description: "Expected matching value.",
Type: schema.TypeString,
Optional: true,
},
},
},
},
"targetxpath": {
Description: "Expected structure if `operator` is `validatesXPath`. Exactly one nested block is allowed with the structure below.",
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"operator": {
Description: "The specific operator to use on the path.",
Type: schema.TypeString,
Required: true,
},
"xpath": {
Description: "The xpath to assert.",
Type: schema.TypeString,
Required: true,
},
"targetvalue": {
Description: "Expected matching value.",
Type: schema.TypeString,
Optional: true,
},
},
},
},
"timings_scope": {
Description: "Timings scope for response time assertions.",
Type: schema.TypeString,
Optional: true,
ValidateDiagFunc: validators.ValidateEnumValue(datadogV1.NewSyntheticsAssertionTimingsScopeFromValue),
},
},
},
}
}
func syntheticsTestOptionsRetry() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"count": {
Description: "Number of retries needed to consider a location as failed before sending a notification alert. Maximum value: `3` for `api` tests, `2` for `browser` and `mobile` tests.",
Type: schema.TypeInt,
Default: 0,
Optional: true,
},
"interval": {
Description: "Interval between a failed test and the next retry in milliseconds. Maximum value: `5000`.",
Type: schema.TypeInt,
Default: 300,
Optional: true,
},
},
},
}
}
func syntheticsTestAdvancedSchedulingTimeframes() *schema.Schema {
return &schema.Schema{
Description: "Array containing objects describing the scheduling pattern to apply to each day.",
Type: schema.TypeSet,
Required: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"day": {
Description: "Number representing the day of the week",
Type: schema.TypeInt,
Required: true,
ValidateFunc: validation.IntBetween(1, 7),
},
"from": {
Description: "The hour of the day on which scheduling starts.",
Type: schema.TypeString,
Required: true,
},
"to": {
Description: "The hour of the day on which scheduling ends.",
Type: schema.TypeString,
Required: true,
},
},
},
}
}
func syntheticsTestAdvancedScheduling() *schema.Schema {
return &schema.Schema{
Description: "Object containing timeframes and timezone used for advanced scheduling.",
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"timeframes": syntheticsTestAdvancedSchedulingTimeframes(),
"timezone": {
Description: "Timezone in which the timeframe is based.",
Type: schema.TypeString,
Required: true,
},
},
},
}
}
func syntheticsTestOptionsList() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"allow_insecure": syntheticsAllowInsecureOption(),
"follow_redirects": syntheticsFollowRedirectsOption(),
"tick_every": {
Description: "How often the test should run (in seconds).",
Type: schema.TypeInt,
Required: true,
ValidateFunc: validation.IntBetween(30, 604800),
},
"scheduling": syntheticsTestAdvancedScheduling(),
"accept_self_signed": {
Description: "For SSL test, whether or not the test should allow self signed certificates.",
Type: schema.TypeBool,
Optional: true,
},
"min_location_failed": {
Description: "Minimum number of locations in failure required to trigger an alert.",
Type: schema.TypeInt,
Default: 1,
Optional: true,
},
"min_failure_duration": {
Description: "Minimum amount of time in failure required to trigger an alert (in seconds). Default is `0`.",
Type: schema.TypeInt,
Optional: true,
},
"monitor_name": {
Description: "The monitor name is used for the alert title as well as for all monitor dashboard widgets and SLOs.",
Type: schema.TypeString,
Optional: true,
},
"monitor_options": {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"renotify_interval": {
Description: "Specify a renotification frequency in minutes. Values available by default are `0`, `10`, `20`, `30`, `40`, `50`, `60`, `90`, `120`, `180`, `240`, `300`, `360`, `720`, `1440`.",
Type: schema.TypeInt,
Default: 0,
Optional: true,
},
"renotify_occurrences": {
Description: "The number of times a monitor renotifies. It can only be set if `renotify_interval` is set.",
Type: schema.TypeInt,
Optional: true,
},
},
},
},
"monitor_priority": {
Type: schema.TypeInt,
Optional: true,
ValidateFunc: validation.IntBetween(1, 5),
},
"restricted_roles": {
Deprecated: "This field is no longer supported by the Datadog API. Please use `datadog_restriction_policy` instead.",
Description: "A list of role identifiers pulled from the Roles API to restrict read and write access.",
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"retry": syntheticsTestOptionsRetry(),
"no_screenshot": {
Description: "Prevents saving screenshots of the steps.",
Type: schema.TypeBool,
Optional: true,
},
"check_certificate_revocation": {
Description: "For SSL test, whether or not the test should fail on revoked certificate in stapled OCSP.",
Type: schema.TypeBool,
Optional: true,
},
"ci": {
Description: "CI/CD options for a Synthetic test.",
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"execution_rule": {
Type: schema.TypeString,
Description: "Execution rule for a Synthetics test.",
ValidateDiagFunc: validators.ValidateEnumValue(datadogV1.NewSyntheticsTestExecutionRuleFromValue),
Optional: true,
},
},
},
},
"rum_settings": {
Description: "The RUM data collection settings for the Synthetic browser test.",
Type: schema.TypeList,
MaxItems: 1,
DiffSuppressFunc: func(key, old, new string, d *schema.ResourceData) bool {
if strings.Contains(key, "is_enabled") {
if new != "true" && old != "true" {
return true
}
} else {
if rum_settings, ok := d.GetOk("options_list.0.rum_settings.0"); ok {
settings := rum_settings.(map[string]interface{})
isEnabled := settings["is_enabled"]
if !isEnabled.(bool) {
return true
}
}
}
return false
},
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"is_enabled": {
Type: schema.TypeBool,
Description: "Determines whether RUM data is collected during test runs.",
Required: true,
},
"application_id": {
Type: schema.TypeString,
Description: "RUM application ID used to collect RUM data for the browser test.",
Optional: true,
},
"client_token_id": {
Type: schema.TypeInt,
Description: "RUM application API key ID used to collect RUM data for the browser test.",
Sensitive: true,
Optional: true,
},
},
},
Optional: true,
},
"ignore_server_certificate_error": {
Description: "Ignore server certificate error for browser tests.",
Type: schema.TypeBool,
Optional: true,
},
"disable_csp": {
Description: "Disable Content Security Policy for browser tests.",
Type: schema.TypeBool,
Optional: true,
},
"disable_cors": {
Description: "Disable Cross-Origin Resource Sharing for browser tests.",
Type: schema.TypeBool,
Optional: true,
},
"initial_navigation_timeout": {
Description: "Timeout before declaring the initial step as failed (in seconds) for browser tests.",
Type: schema.TypeInt,
Optional: true,
},
"http_version": syntheticsHttpVersionOption(),
},
},
}
}
func syntheticsMobileTestOptionsList() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"min_failure_duration": {
Description: "Minimum amount of time in failure required to trigger an alert (in seconds). Default is `0`.",
Type: schema.TypeInt,
Optional: true,
},
"retry": syntheticsTestOptionsRetry(),
"tick_every": {
Description: "How often the test should run (in seconds).",
Type: schema.TypeInt,
Required: true,
ValidateFunc: validation.IntBetween(300, 604800),
},
"scheduling": syntheticsTestAdvancedScheduling(),
"monitor_name": {
Description: "The monitor name is used for the alert title as well as for all monitor dashboard widgets and SLOs.",
Type: schema.TypeString,
Optional: true,
},
"monitor_options": {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"renotify_interval": {
Description: "Specify a renotification frequency in minutes. Values available by default are `0`, `10`, `20`, `30`, `40`, `50`, `60`, `90`, `120`, `180`, `240`, `300`, `360`, `720`, `1440`.",
Type: schema.TypeInt,
Default: 0,
Optional: true,
},
"escalation_message": {
Type: schema.TypeString,
Optional: true,
},
"renotify_occurrences": {
Description: "The number of times a monitor renotifies. It can only be set if `renotify_interval` is set.",
Type: schema.TypeInt,
Optional: true,
},
"notification_preset_name": {
Type: schema.TypeString,
Optional: true,
ValidateDiagFunc: validators.ValidateEnumValue(datadogV1.NewSyntheticsTestOptionsMonitorOptionsNotificationPresetNameFromValue),
},
},
},
},
"monitor_priority": {
Type: schema.TypeInt,
Optional: true,
ValidateFunc: validation.IntBetween(1, 5),
},
"restricted_roles": {
Deprecated: "This field is no longer supported by the Datadog API. Please use `datadog_restriction_policy` instead.",
Description: "A list of role identifiers pulled from the Roles API to restrict read and write access.",
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"bindings": {
Description: "Restriction policy bindings for the Synthetic mobile test. Should not be used in parallel with a `datadog_restriction_policy` resource",
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"principals": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"relation": {
Type: schema.TypeString,
Optional: true,
ValidateDiagFunc: validators.ValidateEnumValue(datadogV1.NewSyntheticsTestRestrictionPolicyBindingRelationFromValue),
},
},
},
},
"ci": {
Description: "CI/CD options for a Synthetic test.",
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"execution_rule": {
Type: schema.TypeString,
Description: "Execution rule for a Synthetics test.",
Required: true,
ValidateDiagFunc: validators.ValidateEnumValue(datadogV1.NewSyntheticsTestExecutionRuleFromValue),
},
},
},
},
"default_step_timeout": {
Type: schema.TypeInt,
Optional: true,
ValidateFunc: validation.IntBetween(1, 300),
},
"device_ids": {
Type: schema.TypeList,
Required: true,
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateDiagFunc: validators.ValidateNonEmptyStrings,
},
},
"no_screenshot": {
Description: "Prevents saving screenshots of the steps.",
Type: schema.TypeBool,
Optional: true,
},
"verbosity": {
Type: schema.TypeInt,
Optional: true,
ValidateFunc: validation.IntBetween(0, 5),
},
"allow_application_crash": {
Type: schema.TypeBool,
Optional: true,
},
"disable_auto_accept_alert": {
Type: schema.TypeBool,
Optional: true,
},
"mobile_application": {
Type: schema.TypeList,
Required: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"application_id": {
Type: schema.TypeString,
Required: true,
},
"reference_id": {
Type: schema.TypeString,
Required: true,
},
"reference_type": {
Type: schema.TypeString,
Required: true,
ValidateDiagFunc: validators.ValidateEnumValue(datadogV1.NewSyntheticsMobileTestsMobileApplicationReferenceTypeFromValue),
},
},
},
},
},
},
}
}
func syntheticsTestAPIStep() *schema.Schema {
requestElemSchema := syntheticsTestRequest()
// In test `options_list` for single API tests, but in `api_step.request_definition` for API steps.
requestElemSchema.Schema["allow_insecure"] = syntheticsAllowInsecureOption()