Resource (datadog_synthetics_test)

Provides a Datadog synthetics test resource. This can be used to create and manage Datadog synthetics test.

Warning

Starting from version 3.1.0+, the direct usage of global variables in the configuration is deprecated, in favor of local variables of type global. As an example, if you were previously using {{ GLOBAL_VAR }} directly in your configuration, add a config_variable of type global with the id matching the id of the global variable GLOBAL_VAR, which can be found in the Synthetics UI or from the output of the datadog_synthetics_global_variable resource. The name can be chosen freely.

In practice, it means going from (simplified configuration):

url = https://{{ GLOBAL_VAR }}

to

config_variable {
  name = "LOCAL_VAR"
  id = [your_global_variable_id]
  type = "global"
}

which you can now use in your request definition:

url = https://{{ LOCAL_VAR }}

Example Usage

# Example Usage (Synthetics API test)
# Create a new Datadog Synthetics API/HTTP test on https://www.example.org
resource "datadog_synthetics_test" "test_uptime" {
  name      = "An Uptime test on example.org"
  type      = "api"
  subtype   = "http"
  status    = "live"
  message   = "Notify @pagerduty"
  locations = ["aws:eu-central-1"]
  tags      = ["foo:bar", "foo", "env:test"]

  request_definition {
    method = "GET"
    url    = "https://www.example.org"
  }

  request_headers = {
    Content-Type = "application/json"
  }

  assertion {
    type     = "statusCode"
    operator = "is"
    target   = "200"
  }

  options_list {
    tick_every = 900
    retry {
      count    = 2
      interval = 300
    }
    monitor_options {
      renotify_interval = 120
    }
  }
}


# Example Usage (Authenticated API test)
# Create a new Datadog Synthetics API/HTTP test on https://www.example.org
resource "datadog_synthetics_test" "test_api" {
  name      = "An API test on example.org"
  type      = "api"
  subtype   = "http"
  status    = "live"
  message   = "Notify @pagerduty"
  locations = ["aws:eu-central-1"]
  tags      = ["foo:bar", "foo", "env:test"]

  request_definition {
    method = "GET"
    url    = "https://www.example.org"
  }

  request_headers = {
    Content-Type   = "application/json"
    Authentication = "Token: 1234566789"
  }

  assertion {
    type     = "statusCode"
    operator = "is"
    target   = "200"
  }

  options_list {
    tick_every = 900
    retry {
      count    = 2
      interval = 300
    }
    monitor_options {
      renotify_interval = 120
    }
  }
}


# Example Usage (Synthetics SSL test)
# Create a new Datadog Synthetics API/SSL test on example.org
resource "datadog_synthetics_test" "test_ssl" {
  name      = "An API test on example.org"
  type      = "api"
  subtype   = "ssl"
  status    = "live"
  message   = "Notify @pagerduty"
  locations = ["aws:eu-central-1"]
  tags      = ["foo:bar", "foo", "env:test"]

  request_definition {
    host = "example.org"
    port = 443
  }

  assertion {
    type     = "certificate"
    operator = "isInMoreThan"
    target   = 30
  }

  options_list {
    tick_every         = 900
    accept_self_signed = true
  }
}


# Example Usage (Synthetics TCP test)
# Create a new Datadog Synthetics API/TCP test on example.org
resource "datadog_synthetics_test" "test_tcp" {
  name      = "An API test on example.org"
  type      = "api"
  subtype   = "tcp"
  status    = "live"
  message   = "Notify @pagerduty"
  locations = ["aws:eu-central-1"]
  tags      = ["foo:bar", "foo", "env:test"]

  request_definition {
    host = "example.org"
    port = 443
  }

  assertion {
    type     = "responseTime"
    operator = "lessThan"
    target   = 2000
  }

  config_variable {
    type = "global"
    name = "MY_GLOBAL_VAR"
    id   = "76636cd1-82e2-4aeb-9cfe-51366a8198a2"
  }

  options_list {
    tick_every = 900
  }
}


# Example Usage (Synthetics DNS test)
# Create a new Datadog Synthetics API/DNS test on example.org
resource "datadog_synthetics_test" "test_dns" {
  name      = "An API test on example.org"
  type      = "api"
  subtype   = "dns"
  status    = "live"
  message   = "Notify @pagerduty"
  locations = ["aws:eu-central-1"]
  tags      = ["foo:bar", "foo", "env:test"]

  request_definition {
    host = "example.org"
  }

  assertion {
    type     = "recordSome"
    operator = "is"
    property = "A"
    target   = "0.0.0.0"
  }

  options_list {
    tick_every = 900
  }
}


# Example Usage (Synthetics Multistep API test)
# Create a new Datadog Synthetics Multistep API test
resource "datadog_synthetics_test" "test_multi_step" {
  name      = "Multistep API test"
  type      = "api"
  subtype   = "multi"
  status    = "live"
  locations = ["aws:eu-central-1"]
  tags      = ["foo:bar", "foo", "env:test"]

  api_step {
    name    = "An API test on example.org"
    subtype = "http"

    assertion {
      type     = "statusCode"
      operator = "is"
      target   = "200"
    }

    request_definition {
      method = "GET"
      url    = "https://example.org"
    }

    request_headers = {
      Content-Type   = "application/json"
      Authentication = "Token: 1234566789"
    }
  }

  api_step {
    name    = "An API test on example.org"
    subtype = "http"

    assertion {
      type     = "statusCode"
      operator = "is"
      target   = "200"
    }

    request_definition {
      method = "GET"
      url    = "http://example.org"
    }
  }

  options_list {
    tick_every         = 900
    accept_self_signed = true
  }
}


# Example Usage (Synthetics Browser test)
# Create a new Datadog Synthetics Browser test starting on https://www.example.org
resource "datadog_synthetics_test" "test_browser" {
  name       = "A Browser test on example.org"
  type       = "browser"
  status     = "paused"
  message    = "Notify @qa"
  device_ids = ["laptop_large"]
  locations  = ["aws:eu-central-1"]
  tags       = []

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

  browser_step {
    name = "Check current url"
    type = "assertCurrentUrl"
    params {
      check = "contains"
      value = "datadoghq"
    }
  }

  browser_step {
    name = "Test a downloaded file"
    type = "assertFileDownload"
    params {
      file = jsonencode(
        {
          md5 = "abcdef1234567890" // MD5 hash of the file
          sizeCheck = {
            type = "equals" // "equals", "greater", "greaterEquals", "lower", 
            // "lowerEquals", "notEquals", "between"
            value = 1
            // min   = 1      // only used for "between"
            // max   = 1      // only used for "between"
          }
          nameCheck = {
            type = "contains" // "contains", "equals", "isEmpty", "matchRegex", 
            // "notContains", "notIsEmpty", "notEquals", 
            // "notStartsWith", "startsWith"
            value = ".xls"
          }
        }
      )
    }
  }

  browser_variable {
    type    = "text"
    name    = "MY_PATTERN_VAR"
    pattern = "{{numeric(3)}}"
    example = "597"
  }

  browser_variable {
    type    = "email"
    name    = "MY_EMAIL_VAR"
    pattern = "jd8-afe-ydv.{{ numeric(10) }}@synthetics.dtdg.co"
    example = "jd8-afe-ydv.4546132139@synthetics.dtdg.co"
  }

  browser_variable {
    type = "global"
    name = "MY_GLOBAL_VAR"
    id   = "76636cd1-82e2-4aeb-9cfe-51366a8198a2"
  }

  options_list {
    tick_every = 3600
  }
}

# Example Usage (GRPC API test)
# Create a new Datadog GRPC API test starting on google.org:50050
resource "datadog_synthetics_test" "grpc" {
  type    = "api"
  subtype = "grpc"
  request_definition {
    method           = "GET"
    host             = "google.com"
    port             = 50050
    service          = "Hello"
    plain_proto_file = <<EOT
syntax = "proto3";
option java_multiple_files = true;
option java_package = "io.grpc.examples.helloworld";
option java_outer_classname = "HelloWorldProto";
option objc_class_prefix = "HLW";
package helloworld;
// The greeting service definition.
service Greeter {
    // Sends a greeting
    rpc SayHello (HelloRequest) returns (HelloReply) {}
}
// The request message containing the user's name.
message HelloRequest {
    string name = 1;
}
// The response message containing the greetings
message HelloReply {
    string message = 1;
}
EOT
  }
  request_metadata = {
    header = "value"
  }
  assertion {
    type     = "responseTime"
    operator = "lessThan"
    target   = "2000"
  }
  assertion {
    operator = "is"
    type     = "grpcHealthcheckStatus"
    target   = 1
  }
  assertion {
    operator = "is"
    target   = "proto target"
    type     = "grpcProto"
  }
  assertion {
    operator = "is"
    target   = "123"
    property = "property"
    type     = "grpcMetadata"
  }
  locations = ["aws:eu-central-1"]
  options_list {
    tick_every = 60
  }
  name    = "GRPC API test"
  message = "Notify @datadog.user"
  tags    = ["foo:bar", "baz"]
  status  = "paused"
}

Schema

Required

Optional

Read-Only

Nested Schema for api_step

Required:

Optional:

Nested Schema for api_step.assertion

Required:

Optional:

Nested Schema for api_step.assertion.targetjsonpath

Required:

Optional:

Nested Schema for api_step.assertion.targetxpath

Required:

Optional:

Nested Schema for api_step.extracted_value

Required:

Optional:

Nested Schema for api_step.extracted_value.parser

Required:

Optional:

Nested Schema for api_step.request_basicauth

Optional:

Nested Schema for api_step.request_client_certificate

Required:

Nested Schema for api_step.request_client_certificate.cert

Required:

Optional:

Nested Schema for api_step.request_client_certificate.key

Required:

Optional:

Nested Schema for api_step.request_definition

Optional:

Nested Schema for api_step.request_proxy

Required:

Optional:

Nested Schema for api_step.retry

Optional:

Nested Schema for assertion

Required:

Optional:

Nested Schema for assertion.targetjsonpath

Required:

Optional:

Nested Schema for assertion.targetxpath

Required:

Optional:

Nested Schema for browser_step

Required:

Optional:

Nested Schema for browser_step.params

Optional:

Nested Schema for browser_step.params.element_user_locator

Required:

Optional:

Nested Schema for browser_step.params.element_user_locator.value

Required:

Optional:

Nested Schema for browser_step.params.variable

Optional:

Nested Schema for browser_variable

Required:

Optional:

Nested Schema for config_variable

Required:

Optional:

Nested Schema for options_list

Required:

Optional:

Nested Schema for options_list.ci

Optional:

Nested Schema for options_list.monitor_options

Optional:

Nested Schema for options_list.retry

Optional:

Nested Schema for options_list.rum_settings

Required:

Optional:

Nested Schema for options_list.scheduling

Required:

Nested Schema for options_list.scheduling.timeframes

Required:

Nested Schema for request_basicauth

Optional:

Nested Schema for request_client_certificate

Required:

Nested Schema for request_client_certificate.cert

Required:

Optional:

Nested Schema for request_client_certificate.key

Required:

Optional:

Nested Schema for request_definition

Optional:

Nested Schema for request_proxy

Required:

Optional:

Import

Import is supported using the following syntax:

# Synthetics tests can be imported using their public string ID, e.g.
terraform import datadog_synthetics_test.fizz abc-123-xyz