Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[synthetics] support http_version in multi-step API tests #2323

Merged
merged 1 commit into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this temporary?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is temporary and fine to do. We will pin the client to an official released version before releasing the provider

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
Loading