Skip to content

Commit

Permalink
[SYNTH-13257] support http_version in multi-step API tests (#2323)
Browse files Browse the repository at this point in the history
  • Loading branch information
etnbrd committed Mar 19, 2024
1 parent c8c762a commit b13194e
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 63 deletions.
23 changes: 17 additions & 6 deletions datadog/resource_datadog_synthetics_test_.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ func syntheticsTestRequest() *schema.Resource {
Type: schema.TypeString,
Optional: true,
},
"http_version": syntheticsHttpVersionOption(),
},
}
}
Expand Down Expand Up @@ -754,12 +755,7 @@ func syntheticsTestOptionsList() *schema.Schema {
Type: schema.TypeInt,
Optional: true,
},
"http_version": {
Description: "HTTP version to use for a Synthetics API test.",
Type: schema.TypeString,
Optional: true,
ValidateDiagFunc: validators.ValidateEnumValue(datadogV1.NewSyntheticsTestOptionsHTTPVersionFromValue),
},
"http_version": syntheticsHttpVersionOption(),
},
},
}
Expand Down Expand Up @@ -1209,6 +1205,15 @@ func syntheticsFollowRedirectsOption() *schema.Schema {
}
}

func syntheticsHttpVersionOption() *schema.Schema {
return &schema.Schema{
Description: "HTTP version to use for an HTTP request in an API test or step.",
Type: schema.TypeString,
Optional: true,
ValidateDiagFunc: validators.ValidateEnumValue(datadogV1.NewSyntheticsTestOptionsHTTPVersionFromValue),
}
}

func resourceDatadogSyntheticsTestCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
providerConf := meta.(*ProviderConfiguration)
apiInstances := providerConf.DatadogApiInstances
Expand Down Expand Up @@ -1576,6 +1581,9 @@ func buildSyntheticsAPITestStruct(d *schema.ResourceData) *datadogV1.SyntheticsA
request.SetFollowRedirects(requestMap["follow_redirects"].(bool))
request.SetPersistCookies(requestMap["persist_cookies"].(bool))
request.SetNoSavingResponseBody(requestMap["no_saving_response_body"].(bool))
if v, ok := requestMap["http_version"].(string); ok && v != "" {
request.SetHttpVersion(datadogV1.SyntheticsTestOptionsHTTPVersion(v))
}
}

request = *completeSyntheticsTestRequest(request, stepMap["request_headers"].(map[string]interface{}), stepMap["request_query"].(map[string]interface{}), stepMap["request_basicauth"].([]interface{}), stepMap["request_client_certificate"].([]interface{}), stepMap["request_proxy"].([]interface{}), map[string]interface{}{})
Expand Down Expand Up @@ -2386,6 +2394,9 @@ func buildLocalRequest(request datadogV1.SyntheticsTestRequest) map[string]inter
if request.HasPersistCookies() {
localRequest["persist_cookies"] = request.GetPersistCookies()
}
if request.HasHttpVersion() {
localRequest["http_version"] = request.GetHttpVersion()
}
if request.HasCompressedJsonDescriptor() {
decodedValue, _ := b64.StdEncoding.DecodeString(request.GetCompressedJsonDescriptor())
decodedBytes := bytes.NewReader(decodedValue)
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2024-01-19T11:58:30.290388+01:00
2024-03-15T22:11:29.12984+01:00

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions datadog/tests/resource_datadog_synthetics_test_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,8 @@ func createSyntheticsAPITestStep(ctx context.Context, accProvider func() (*schem
"datadog_synthetics_test.foo", "options_list.0.ci.0.execution_rule", "blocking"),
resource.TestCheckResourceAttr(
"datadog_synthetics_test.foo", "options_list.0.ignore_server_certificate_error", "true"),
resource.TestCheckResourceAttr(
"datadog_synthetics_test.foo", "options_list.0.http_version", "http2"),
resource.TestCheckResourceAttr(
"datadog_synthetics_test.foo", "name", testName),
resource.TestCheckResourceAttr(
Expand Down Expand Up @@ -4122,6 +4124,8 @@ func createSyntheticsMultistepAPITest(ctx context.Context, accProvider func() (*
"datadog_synthetics_test.multi", "api_step.0.request_definition.0.follow_redirects", "true"),
resource.TestCheckResourceAttr(
"datadog_synthetics_test.multi", "api_step.0.request_definition.0.no_saving_response_body", "true"),
resource.TestCheckResourceAttr(
"datadog_synthetics_test.multi", "api_step.0.request_definition.0.http_version", "http2"),
resource.TestCheckResourceAttr(
"datadog_synthetics_test.multi", "api_step.0.request_headers.%", "2"),
resource.TestCheckResourceAttr(
Expand Down Expand Up @@ -4300,6 +4304,7 @@ resource "datadog_synthetics_test" "multi" {
allow_insecure = true
follow_redirects = true
no_saving_response_body = true
http_version = "http2"
}
request_headers = {
Accept = "application/json"
Expand Down
4 changes: 3 additions & 1 deletion docs/resources/synthetics_test.md
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,7 @@ Optional:
- `dns_server_port` (Number) DNS server port to use for DNS tests.
- `follow_redirects` (Boolean) Determines whether or not the API HTTP test should follow redirects.
- `host` (String) Host name to perform the test with.
- `http_version` (String) HTTP version to use for an HTTP request in an API test or step. Valid values are `http1`, `http2`, `any`.
- `message` (String) For UDP and websocket tests, message to send with the request.
- `method` (String) 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`.
- `no_saving_response_body` (Boolean) Determines whether or not to save the response body.
Expand Down Expand Up @@ -809,7 +810,7 @@ Optional:
- `disable_cors` (Boolean) Disable Cross-Origin Resource Sharing for browser tests.
- `disable_csp` (Boolean) Disable Content Security Policy for browser tests.
- `follow_redirects` (Boolean) Determines whether or not the API HTTP test should follow redirects.
- `http_version` (String) HTTP version to use for a Synthetics API test. Valid values are `http1`, `http2`, `any`.
- `http_version` (String) HTTP version to use for an HTTP request in an API test or step. Valid values are `http1`, `http2`, `any`.
- `ignore_server_certificate_error` (Boolean) Ignore server certificate error for browser tests.
- `initial_navigation_timeout` (Number) Timeout before declaring the initial step as failed (in seconds) for browser tests.
- `min_failure_duration` (Number) Minimum amount of time in failure required to trigger an alert (in seconds). Default is `0`.
Expand Down Expand Up @@ -950,6 +951,7 @@ Optional:
- `dns_server` (String) DNS server to use for DNS tests (`subtype = "dns"`).
- `dns_server_port` (Number) DNS server port to use for DNS tests.
- `host` (String) Host name to perform the test with.
- `http_version` (String) HTTP version to use for an HTTP request in an API test or step. Valid values are `http1`, `http2`, `any`.
- `message` (String) For UDP and websocket tests, message to send with the request.
- `method` (String) 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`.
- `no_saving_response_body` (Boolean) Determines whether or not to save the response body.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module github.com/terraform-providers/terraform-provider-datadog

require (
github.com/DataDog/datadog-api-client-go/v2 v2.24.0
github.com/DataDog/datadog-api-client-go/v2 v2.24.1-0.20240313200128-5ad8b96de316
github.com/DataDog/dd-sdk-go-testing v0.0.0-20211116174033-1cd082e322ad
github.com/google/uuid v1.5.0
github.com/hashicorp/go-cleanhttp v0.5.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/DataDog/datadog-api-client-go/v2 v2.24.0 h1:7G+eyezFM8gHq5dOHcrQcGVxrXnwPqX2yYHxsLiq3iM=
github.com/DataDog/datadog-api-client-go/v2 v2.24.0/go.mod h1:QKOu6vscsh87fMY1lHfLEmNSunyXImj8BUaUWJXOehc=
github.com/DataDog/datadog-api-client-go/v2 v2.24.1-0.20240313200128-5ad8b96de316 h1:3nW3CchcgmV/mBxOq1GCwrokOtwa/TOmaS3S7wm9qwQ=
github.com/DataDog/datadog-api-client-go/v2 v2.24.1-0.20240313200128-5ad8b96de316/go.mod h1:QKOu6vscsh87fMY1lHfLEmNSunyXImj8BUaUWJXOehc=
github.com/DataDog/datadog-go v4.4.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
github.com/DataDog/datadog-go v4.8.3+incompatible h1:fNGaYSuObuQb5nzeTQqowRAd9bpDIRRV4/gUtIBjh8Q=
github.com/DataDog/datadog-go v4.8.3+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
Expand Down

0 comments on commit b13194e

Please sign in to comment.