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

Extracted Value configuration in Synthetic Test API Step passes "null" value for the parser of type "raw" #2590

Open rshah28 opened 1 month ago

rshah28 commented 1 month ago

Datadog Terraform Provider Version

3.44.1

Terraform Version

v1.5.3

What resources or data sources are affected?

datadog_synthetics_test

Terraform Configuration Files

resource "datadog_synthetics_test" "availability_check" {
  name      = "Service Availability"
  type      = "api"
  subtype   = "multi"
  locations = var.regions
  message   = var.alert_recipients
  tags      = [local.env_tag]
  status    = "live"

  options_list {
    monitor_name     = "Service Availability"
    monitor_priority = 1
    tick_every       = 60 # run every minute
    retry {
      count    = 2
      interval = 300
    }
    monitor_options {
      renotify_interval = 30
    }
  }

  config_variable {
    type = "global"
    id   = datadog_synthetics_global_variable.user_password[0].id
    name = datadog_synthetics_global_variable.user_password[0].name
  }

  config_variable {
    type = "global"
    id   = datadog_synthetics_global_variable.auth_request_body[0].id
    name = datadog_synthetics_global_variable.auth_request_body[0].name
  }

  api_step {
    name        = "Create Session"
    subtype     = "http"
    is_critical = true

    request_definition {
      method  = "GET"
      url     = var.app_url_for_synthetics
      timeout = 60
    }

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

    extracted_value {
      name  = "AUTH_SESSION_COOKIE"
      type  = "http_header"
      field = "set-cookie"
      parser {
        type  = "regex"
        value = "auth-session=[a-zA-Z0-9]+;"
      }
    }

    extracted_value {
      name  = "AUTHORIZE_URL"
      type  = "http_header"
      field = "location"
      parser {
        type = "raw"
      }
    }
  }
 }
}

Relevant debug or panic output

Error: error updating synthetics API test from /api/v1/synthetics/tests/api/{public_id}: 400 Bad Request: {"errors":["'extractedValues' value '{'field': 'location', 'name': 'AUTHORIZE_URL', 'parser': {'type': 'raw', 'value': ''}, 'secure': False, 'type': 'http_header'}' is invalid"]}

Expected Behavior

Per API docs the "value" config should not be set for the "raw" type parser. https://docs.datadoghq.com/api/latest/synthetics/#edit-an-api-test

Actual Behavior

It fails to edit the existing Synthetic Test when upgrading the terraform datadog provider version from 3.32.0 to 3.44.1

Steps to Reproduce

terraform apply

Important Factoids

No response

References

No response

Lord-Gusarov commented 1 month ago

Datadog Terraform Provider Version

= 3.39.0

Unable to create or update tests with the extracted_value option and the parser type set to 'raw'. The Provider version had not been changed. Tried with multiple Provider versions and as recent as version 3.44.1

Relevant debug or panic output

Error: error creating synthetics API test from /api/v1/synthetics/tests/api: 400 Bad Request: {"errors":["'extractedValues' value '{'field': 'location', 'name': 'OKTA_REDIRECT_URL', 'parser': {'type': 'raw', 'value': ''}, 'secure': False, 'type': 'http_header'}' is invalid"]}

Lord-Gusarov commented 1 month ago

Workaround:

Change the parser type to regex and use value .* as the regex.

From:

     extracted_value {
      name  = "AUTHORIZE_URL"
      type  = "http_header"
      field = "location"
      parser {
        type = "raw"
      }

to:

     extracted_value {
      name  = "AUTHORIZE_URL"
      type  = "http_header"
      field = "location"
      parser {
        type = "regex"
        value = ".*"
      }
rshah28 commented 1 month ago

@Lord-Gusarov thanks! will give it a try.