DataDog / terraform-provider-datadog

Terraform Datadog provider
https://www.terraform.io/docs/providers/datadog/
Mozilla Public License 2.0
403 stars 379 forks source link

[datadog_synthetics_test] Add javascript assertion to Synthetics Assertion #2576

Closed RomainGuarinoni closed 1 month ago

RomainGuarinoni commented 2 months ago

SYNTH-14849

Context

We want to add the capabilities to create JS assertions with terraform

[!Important] Because the javascript assertion does not contains any operator, we need to make the operator field of an assertion Optional.

Because we cannot validate a field based on another field in schema right now, it means we cannot make the operator optional only if type is javascript and make it required otherwise.

This implies that we cannot validate anymore if the user forgot to add an operator for a non javascript assertion, and terraform will still perform the request to dogweb and then display the validation error from dogweb.

But we still have the operator validation, meaning terraform will fail if the user provide a wrong operator value

Now, we have thew options to deal with this issue:

  1. Do nothing about it, and let the terraform accept an assertion with no operator (other than javascript assertion) and then display the error from dogweb :
{"errors":["'assertions' value '{'operator': '', 'target': 2000, 'type': 'responseTime'}' is invalid"]}
  1. Add an special operator for this kind of case where we don't really need any operator, such as noOperator or something like this. This would require a lot of work in the worker, frontend and api spec because we already created a bunch of type for this assertion assuming there is no operator
  2. Create a new schema for assertion without operator so we still have the required operator for regular assertions, and no operator for the js assertion, for example:
  assertion {
    type     = "responseTime"
    operator = "is"
    target   = "200"
  }
  javascript_assertion {
    type = "javascript"
    code = "console.log('hello world')"
  }

Change

QA

Tested locally with the provider and it works