terraform-provider-datadog icon indicating copy to clipboard operation
terraform-provider-datadog copied to clipboard

Browser synthetic test creation fails with `'bucketKey' is a required property`

Open gabrielhof opened this issue 4 years ago • 9 comments

Hi there,

I'm trying to create a basic browser synthetic test, but I'm facing the following error:

Step 0 has invalid params: 'bucketKey' is a required property

Terraform Version

➜ terraform -v
Terraform v0.14.6
+ provider registry.terraform.io/datadog/datadog v2.21.0

Affected Resource(s)

  • datadog_synthetics_test

Terraform Configuration Files

resource "datadog_synthetics_test" "basic_browser_test" {
  type = "browser"
  name = "Basic Browser Test"
  status = "live"

  locations = ["aws:us-east-2"]
  device_ids = ["chrome.laptop_large"]

  options_list {
    tick_every = 3600
  }

  message = <<-EOT
  *Basic Browser Test*

  {{#is_alert}}
  :red-alert: Basic Browser Test is failing.
  {{/is_alert}}

  {{#is_alert_recovery}}
  :green-alert: Basic Browser Test has now recovered.
  {{/is_alert_recovery}}
  EOT

  request_definition {
    method = "GET"
    url = "https://google.com"
  }

  browser_step {
    type = "typeText"
    name = "Input something in the search field"

    params {
      element = jsonencode({
        userLocator = {
          values = [{
            type = "css"
            value = "input[name='q']"
          }]
        }

      })

      value = "Some search"
    }
  }
}

Debug Output

https://gist.github.com/gabrielhof/00b22360384b2bd8344602b926648196

Panic Output

No panic produced.

Expected Behavior

The synthetic test should be successfully created with the configured browser step or either the expected value for the bucketId property should be present in the documentation.

Actual Behavior

The synthetic test gets created but without any steps. Also, the created test is not stored inside the terraform state, causing the next executions to duplicate it.

Steps to Reproduce

  1. Created a main.tf file with the provided example
  2. Execute terraform apply -auto-approve

gabrielhof avatar Feb 17 '21 19:02 gabrielhof

When trying to specify a random value for the bucketId property, I end up getting a different error:

Error: error creating synthetics test: 400 Bad Request: {"errors": ["Step 0 has invalid params: Additional properties are not allowed (u'bucketId' was unexpected)"]}

It seems this property is both required and not expected to be there (or I'm proving an invalid value for it).

Edit I don't know if it might help, but if I import an existing browser test into the configured terraform resource and ran apply in order to update the imported resource, the test is successfully updated.

gabrielhof avatar Feb 17 '21 19:02 gabrielhof

Is there any plan/timeline to resolve this? Let us know if I can help to make PR etc.

~I am not familiar with this bucketId property. But I was comparing the payload sent by the TF provider and the Datadog API docs, and found that potentially one mandatory field is left blank.~

~https://user-images.githubusercontent.com/898384/131792467-411147f4-6ed8-4332-81e1-4080a2632f4a.png~

Edit:

I think I figure out the problem. I don't think it's the terraform provider issue. I think there are missing additional "elements", in addition to userLocator. Unfortunately, this isn't well documented in Datadog API docs. I checked their typescript sdk, and "element" is marked as any. So, that's not helping at all. Error message is not well understood either.

You can try to add more "locators" and it should fix it.

 browser_step {
    type = "typeText"
    name = "Input something in the search field"

    params {
      element = jsonencode({
        multiLocator = {ab = ..., co = ..., etc}
        targetOuterHTML = "...."
        userLocator = {
          values = [{
            type = "css"
            value = "input[name='q']"
          }]
        }

      })

      value = "Some search"
    }
  }
}

Unforturnately, those "multiLocator" and "targetOuterHTML" mechanism isn't well documented either.

What I did for my case was to create step interactively via the web first. I would then get remaining "locators" by fetching it from datadog API, like so:

curl -X GET "https://api.datadoghq.com/api/v1/synthetics/tests/browser/xxx-xxx-xxx" \
-H "Content-Type: application/json" \
-H "DD-API-KEY: xxxxxxxxxxxxxxx" \
-H "DD-APPLICATION-KEY: xxxxxxxxxxxxxx"

Not a perfect solution. Sadly, the "multiLocator" is not meant for mere mortals like us.

image

faizhasim avatar Sep 02 '21 06:09 faizhasim

I also faced same issue. As @faizhasim pointed out the issue is because of multiLocator requirement as "element" (and your solution looks great!)

The easiest way to get around is sadly to just create the test on UI and then use terraformer to import the test as terraform code (and strip it down a bit to remove unnecessary attributes).

Is "multiLocator" a proprietary method used by Datadog to locate element? I couldn't find much information to generate element in the similar format.

1995YogeshSharma avatar Sep 07 '21 23:09 1995YogeshSharma

Dev in our team also figure out that as long as you pass the multiLocator, even with ab="" (empty string), it would work too. But, not sure whether that's intended by Datadog.

I think the multiLocator isn't documented and it's part of their custom query/dsl, that get generated when you interact on the UI. There's no way I would use that even if they provide the documentations lol.

faizhasim avatar Sep 07 '21 23:09 faizhasim

@1995YogeshSharma excuse me, i face the same problem. and could you tell me more about the solution that you mention : """The easiest way to get around is sadly to just create the test on UI and then use terraformer to import the test as terraform code (and strip it down a bit to remove unnecessary attributes). """

How can i use terraformer to import the test as terraform code ? thanks so much.

huynv9699 avatar Oct 13 '21 11:10 huynv9699

Hey @huynv9699 ,

Here's the terraformer command to import a synthetic test terraformer import datadog --resources=synthetics_test --filter=synthetics_test={{TEST_IDX_IN_URL}} --api-key DD_API_KEY --app-key DD_APP_KEY

To make it work -

  • You install "terraformer" on your system
  • Create a synthetic test using datadog UI
  • Run the terraformer command mentioned above in a folder, it would create a "generated" folder with terraform code inside it.
  • Keep the necessary part from the generated code and add it to your terraform code to create / maintain test using terraform.

1995YogeshSharma avatar Oct 16 '21 11:10 1995YogeshSharma

@1995YogeshSharma, the tool is so good, it helped me so much. thanks a lot.

huynv9699 avatar Oct 17 '21 10:10 huynv9699

@1995YogeshSharma, thanks for the solution! I'm having troubles using the terraformer command you mentioned above. What is the "TEST_IDX_IN_URL"?

The error I'm getting when I run it is "no such file or directory"

dillonbaxendell avatar Jul 27 '22 14:07 dillonbaxendell

Hey @dillonbaxendell , you might have already figured it out.

Just for anyone who stumbles upon this, when you create test using UI, url for the test may look something like https://app.datadoghq.com/synthetics/details/yjs-cv7-jk6, "yjs-cv7-jk6" is TEST_IDX_IN_URL in this case.

The error I'm getting when I run it is "no such file or directory"

Although, this error should not be related to that

1995YogeshSharma avatar Sep 18 '22 11:09 1995YogeshSharma

Hello all, the mentioned config should now be working with the latest provider version. Going to go ahead and close this issue out but feel free to reply/re-open if you run into the same issue. Thanks!

skarimo avatar Dec 29 '22 18:12 skarimo