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

[datadog_synthetics] Add body_type field to SyntheticsTest request_definition #1629

Merged
merged 11 commits into from
Nov 10, 2022
18 changes: 18 additions & 0 deletions datadog/resource_datadog_synthetics_test_.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ func syntheticsTestRequest() *schema.Resource {
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. Defaults to `60`.",
Type: schema.TypeInt,
Expand Down Expand Up @@ -1277,6 +1283,9 @@ func buildSyntheticsAPITestStruct(d *schema.ResourceData) *datadogV1.SyntheticsA
if attr, ok := k.GetOkWith("body"); ok {
request.SetBody(attr.(string))
}
if attr, ok := k.GetOkWith("body_type"); ok {
request.SetBodyType(datadogV1.SyntheticsTestRequestBodyType(attr.(string)))
}
if attr, ok := k.GetOkWith("timeout"); ok {
request.SetTimeout(float64(attr.(int)))
}
Expand Down Expand Up @@ -1374,6 +1383,9 @@ func buildSyntheticsAPITestStruct(d *schema.ResourceData) *datadogV1.SyntheticsA
request.SetMethod(datadogV1.HTTPMethod(requestMap["method"].(string)))
request.SetUrl(requestMap["url"].(string))
request.SetBody(requestMap["body"].(string))
if v, ok := requestMap["body_type"].(string); ok && v != "" {
request.SetBodyType(datadogV1.SyntheticsTestRequestBodyType(v))
}
request.SetTimeout(float64(requestMap["timeout"].(int)))
request.SetAllowInsecure(requestMap["allow_insecure"].(bool))
request.SetFollowRedirects(requestMap["follow_redirects"].(bool))
Expand Down Expand Up @@ -1758,6 +1770,9 @@ func buildSyntheticsBrowserTestStruct(d *schema.ResourceData) *datadogV1.Synthet
if attr, ok := k.GetOkWith("body"); ok {
request.SetBody(attr.(string))
}
if attr, ok := k.GetOkWith("body_type"); ok {
request.SetBodyType(datadogV1.SyntheticsTestRequestBodyType(attr.(string)))
}
if attr, ok := k.GetOkWith("timeout"); ok {
request.SetTimeout(float64(attr.(int)))
}
Expand Down Expand Up @@ -2111,6 +2126,9 @@ func buildLocalRequest(request datadogV1.SyntheticsTestRequest) map[string]inter
if request.HasBody() {
localRequest["body"] = request.GetBody()
}
if request.HasBodyType() {
localRequest["body_type"] = request.GetBodyType()
}
if request.HasMethod() {
localRequest["method"] = convertToString(request.GetMethod())
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2022-09-06T21:35:48.291253+02:00
2022-11-10T13:06:26.139859-05:00
133 changes: 118 additions & 15 deletions datadog/tests/cassettes/TestAccDatadogSyntheticsAPITest_Basic.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
2022-11-08T15:54:37.715516+01:00
2022-11-10T13:06:26.139819-05:00

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
2022-09-06T21:35:30.248736+02:00
2022-11-10T13:06:09.724039-05:00
161 changes: 133 additions & 28 deletions datadog/tests/cassettes/TestAccDatadogSyntheticsAPITest_Updated.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
2022-11-08T15:55:05.545535+01:00
2022-11-10T13:06:09.72404-05:00

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
2022-09-06T21:36:18.248855+02:00
2022-11-10T13:07:15.578709-05:00

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
2022-10-19T09:52:38.20238-04:00
2022-11-10T13:04:25.395068-05:00

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
2022-10-19T09:52:06.698853-04:00
2022-11-10T13:05:50.841582-05:00

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
2022-10-19T09:52:06.698853-04:00
2022-11-10T13:05:50.841582-05:00

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
2022-10-19T09:52:56.69711-04:00
2022-11-10T13:07:01.055749-05:00

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
2022-04-29T14:29:42.297762+02:00
2022-11-10T13:05:33.753638-05:00

Large diffs are not rendered by default.

31 changes: 24 additions & 7 deletions datadog/tests/resource_datadog_synthetics_test_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,8 @@ func createSyntheticsAPITestStep(ctx context.Context, accProvider func() (*schem
"datadog_synthetics_test.foo", "request_definition.0.timeout", "30"),
resource.TestCheckResourceAttr(
"datadog_synthetics_test.foo", "request_definition.0.body", "this is a body"),
resource.TestCheckResourceAttr(
"datadog_synthetics_test.foo", "request_definition.0.body_type", "text/plain"),
resource.TestCheckResourceAttr(
"datadog_synthetics_test.foo", "request_definition.0.no_saving_response_body", "true"),
resource.TestCheckResourceAttr(
Expand Down Expand Up @@ -598,7 +600,7 @@ func createSyntheticsAPITestStep(ctx context.Context, accProvider func() (*schem
resource.TestCheckResourceAttr(
"datadog_synthetics_test.foo", "options_list.0_list.#", "0"),
resource.TestCheckResourceAttr(
"datadog_synthetics_test.foo", "options_list.0.restricted_roles.0", "abc"),
"datadog_synthetics_test.foo", "options_list.0.restricted_roles.#", "1"),
resource.TestCheckResourceAttr(
"datadog_synthetics_test.foo", "options_list.0.ci.0.execution_rule", "blocking"),
resource.TestCheckResourceAttr(
Expand Down Expand Up @@ -631,6 +633,10 @@ func createSyntheticsAPITestStep(ctx context.Context, accProvider func() (*schem

func createSyntheticsAPITestConfig(uniq string) string {
return fmt.Sprintf(`
resource "datadog_role" "bar" {
name = "%[1]s"
}

resource "datadog_synthetics_test" "foo" {
type = "api"
subtype = "http"
Expand All @@ -639,6 +645,7 @@ resource "datadog_synthetics_test" "foo" {
method = "GET"
url = "https://www.datadoghq.com"
body = "this is a body"
body_type = "text/plain"
timeout = 30
no_saving_response_body = true
}
Expand Down Expand Up @@ -698,7 +705,7 @@ resource "datadog_synthetics_test" "foo" {
}
monitor_name = "%[1]s-monitor"
monitor_priority = 5
restricted_roles = ["abc"]
restricted_roles = ["${datadog_role.bar.id}"]
ci {
execution_rule = "blocking"
}
Expand Down Expand Up @@ -2237,7 +2244,7 @@ func createSyntheticsBrowserTestStep(ctx context.Context, accProvider func() (*s
resource.TestCheckResourceAttr(
"datadog_synthetics_test.bar", "options_list.0.monitor_priority", "5"),
resource.TestCheckResourceAttr(
"datadog_synthetics_test.bar", "options_list.0.restricted_roles.0", "abc"),
"datadog_synthetics_test.bar", "options_list.0.restricted_roles.#", "1"),
resource.TestCheckResourceAttr(
"datadog_synthetics_test.bar", "options_list.0.rum_settings.0.is_enabled", "true"),
resource.TestCheckResourceAttr(
Expand Down Expand Up @@ -2302,6 +2309,9 @@ func createSyntheticsBrowserTestStep(ctx context.Context, accProvider func() (*s

func createSyntheticsBrowserTestConfig(uniq string) string {
return fmt.Sprintf(`
resource "datadog_role" "bar" {
name = "%[1]s"
}
resource "datadog_synthetics_test" "bar" {
type = "browser"

Expand Down Expand Up @@ -2349,7 +2359,7 @@ resource "datadog_synthetics_test" "bar" {
}
monitor_name = "%[1]s-monitor"
monitor_priority = 5
restricted_roles = ["abc"]
restricted_roles = ["${datadog_role.bar.id}"]

no_screenshot = true

Expand Down Expand Up @@ -3516,7 +3526,7 @@ func createSyntheticsMultistepAPITest(ctx context.Context, accProvider func() (*
resource.TestCheckResourceAttr(
"datadog_synthetics_test.multi", "options_list.0.min_location_failed", "1"),
resource.TestCheckResourceAttr(
"datadog_synthetics_test.multi", "options_list.0.restricted_roles.0", "abc"),
"datadog_synthetics_test.multi", "options_list.0.restricted_roles.#", "1"),
resource.TestCheckResourceAttr(
"datadog_synthetics_test.multi", "name", testName),
resource.TestCheckResourceAttr(
Expand Down Expand Up @@ -3629,6 +3639,10 @@ func createSyntheticsMultistepAPITest(ctx context.Context, accProvider func() (*

func createSyntheticsMultistepAPITestConfig(testName string, variableName string) string {
return fmt.Sprintf(`
resource "datadog_role" "bar" {
name = "%[1]s"
}

resource "datadog_synthetics_global_variable" "global_variable" {
name = "%[2]s"
description = "a global variable"
Expand All @@ -3644,8 +3658,8 @@ resource "datadog_synthetics_test" "multi" {
tick_every = 900
min_failure_duration = 0
min_location_failed = 1
restricted_roles = ["abc"]
}
restricted_roles = ["${datadog_role.bar.id}"]
}
name = "%[1]s"
message = "Notify @datadog.user"
tags = ["multistep"]
Expand Down Expand Up @@ -3748,6 +3762,9 @@ func testSyntheticsTestExists(accProvider func() (*schema.Provider, error)) reso
auth := providerConf.Auth

for _, r := range s.RootModule().Resources {
if r.Type != "datadog_synthetics_test" {
continue
}
if _, _, err := apiInstances.GetSyntheticsApiV1().GetTest(auth, r.Primary.ID); err != nil {
return fmt.Errorf("received an error retrieving synthetics test %s", err)
}
Expand Down
2 changes: 2 additions & 0 deletions docs/resources/synthetics_test.md
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ Optional:

- `allow_insecure` (Boolean) Allows loading insecure content for an HTTP test.
- `body` (String) The request body.
- `body_type` (String) Type of the request body. Valid values are `text/plain`, `application/json`, `text/xml`, `text/html`, `application/x-www-form-urlencoded`, `graphql`.
- `certificate_domains` (List of String) 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`.
- `dns_server` (String) DNS server to use for DNS tests (`subtype = "dns"`).
- `dns_server_port` (Number) DNS server port to use for DNS tests.
Expand Down Expand Up @@ -750,6 +751,7 @@ Optional:
Optional:

- `body` (String) The request body.
- `body_type` (String) Type of the request body. Valid values are `text/plain`, `application/json`, `text/xml`, `text/html`, `application/x-www-form-urlencoded`, `graphql`.
- `certificate_domains` (List of String) 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`.
- `dns_server` (String) DNS server to use for DNS tests (`subtype = "dns"`).
- `dns_server_port` (Number) DNS server port to use for DNS tests.
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.4.1-0.20221108101128-e9dfeefa073e
github.com/DataDog/datadog-api-client-go/v2 v2.5.0
github.com/DataDog/dd-sdk-go-testing v0.0.0-20211116174033-1cd082e322ad
github.com/dnaeon/go-vcr v1.0.1
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,8 +1,8 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.34.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.4.1-0.20221108101128-e9dfeefa073e h1:betPumOqvY98AdoZagIKyPmght7lbysK59Jh5mBa1HM=
github.com/DataDog/datadog-api-client-go/v2 v2.4.1-0.20221108101128-e9dfeefa073e/go.mod h1:98b/MtTwSAr/yhTfhCR1oxAqQ/4tMkdrgKH7fYiDA0g=
github.com/DataDog/datadog-api-client-go/v2 v2.5.0 h1:+FRtNnR+IZ4D5lGqEk+f0+dSP7XhKtrlHvdcnTdyny8=
github.com/DataDog/datadog-api-client-go/v2 v2.5.0/go.mod h1:98b/MtTwSAr/yhTfhCR1oxAqQ/4tMkdrgKH7fYiDA0g=
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