Skip to content

Add "xpath" assertion to the "synthetics test" resource #1173

@mikalai-t

Description

@mikalai-t

Hi, folks. Thanks for you job! There is a small issue in the Terraform documentation, I couldn't find anything related to the xpath test (but the jsonpath is pretty well documented). May I ask to add this one as well, please!?

Terraform Version

Terraform v0.13.7

Affected Resource(s)

  • resource "datadog_synthetics_test"

Terraform Configuration Files

# main.tf
resource "datadog_synthetics_test" "www" {
  locations = local.synthetics_www_test_locations
  name = "Status of ${local.synthetics_www_test_endpoint}"
  status = "live"
  type    = "api"

  assertion {
    type     = "responseTime"
    operator = "lessThanOrEqual"
    target   = "5000"
  }
  assertion {
    type     = "statusCode"
    operator = "matches"
    target   = "200|30(1|2)"
  }
  assertion {
    type     = "body"
    operator = "validatesXPath"
    ### what has to be placed here instead of `target` or `targetxpath` ? ###
    target = {
      xPath = "/html/body/div[1]/div[2]/header/div[2]/div/div[1]/ul/ul/li[1]/a"
      operator = "contains"
      targetValue = "Login"
    }
  }

  message = local.synthetics_www_test_message

  options_list {
    tick_every = local.synthetics_www_test_options["tick_every"]
    follow_redirects = true
    min_location_failed = local.synthetics_www_test_options["min_location_failed"]

    monitor_name = "Availability of ${local.synthetics_www_test_endpoint}"
    monitor_options {
      renotify_interval = local.synthetics_www_test_options["renotify_interval"]
    }
    monitor_priority = local.synthetics_www_test_options["monitor_priority"]
  }

  request_definition {
    method = "GET"
    url    = local.synthetics_www_test_endpoint
  }

  subtype = "http"

  tags = [
    "terraform:true",
    "env:${var.env}"
  ]
}
# versions.tf
terraform {
  required_version = ">= 0.13"

  required_providers {
    datadog = {
      source = "datadog/datadog"
      version = "~> 3.2.0"
    }
  }
}

Debug Output

Error: Unsupported argument in case of using targetxpath
Error: Incorrect attribute value type in case of target

Expected Behavior

Terraform must create the specified synthetic test in Datadog

Actual Behavior

Terraform produces an error

Steps to Reproduce

  1. terraform apply

Important Factoids

  • none

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions