Skip to content

Synthetics global variables not visible in multi step API tests #1701

Description

@skolsuper

Hi there,

I have an issue when creating a multi-step API synthetic test referencing global variables. The terraform apply appears to work fine, however when the test runs, it is unable to interpolate the local variables in the request body of the first step.

Terraform Version

Terraform v1.3.1
on darwin_arm64
+ provider registry.terraform.io/datadog/datadog v3.19.1
+ provider registry.terraform.io/hashicorp/aws v4.48.0

Affected Resource(s)

  • datadog_synthetics_global_variable
  • datadog_synthetics_test

Terraform Configuration Files

resource "datadog_synthetics_global_variable" "api_base_url" {
  name  = "API_BASE_URL"
  value = local.api_base_url
}

resource "datadog_synthetics_global_variable" "ux_test_user" {
  name  = "UX_TEST_USER"
  value = local.ux_test_user
}

resource "datadog_synthetics_global_variable" "ux_test_password" {
  name   = "UX_TEST_PASSWORD"
  value  = data.aws_ssm_parameter.ux_test_password.value
  secure = true
}

resource "datadog_synthetics_test" "ux_demo_flow_1" {
  name      = "UX test - Login"
  type      = "api"
  subtype   = "multi"
  status    = "live"
  locations = ["aws:us-east-1"]

  api_step {
    name    = "Login"
    subtype = "http"
    request_headers = {
      Content-Type = "application/json"
    }

    extracted_value {
      name = "AUTH_TOKEN"
      type = "http_body"
      parser {
        type  = "json_path"
        value = "$.session.jwt"
      }
    }

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

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

    request_definition {
      method = "POST"
      url    = "{{ API_BASE_URL }}/api/v1/auth/sign_in"

      body = jsonencode({
        auth = {
          email    = "{{ USER }}",
          password = "{{ PASSWORD }}"
        }
      })
      body_type = "application/json"
    }
  }

  config_variable {
    name = "API_BASE_URL"
    type = "global"
    id   = datadog_synthetics_global_variable.api_base_url.id
  }

  config_variable {
    name = "USER"
    type = "global"
    id   = datadog_synthetics_global_variable.ux_test_user.id
  }

  config_variable {
    name = "PASSWORD"
    type = "global"
    id   = datadog_synthetics_global_variable.ux_test_password.id
  }

  options_list {
    tick_every = 300
  }
}

Debug Output

The configuration plans and applies OK.

Expected Behavior

The global variables should be created, and local variables referencing them within the test. The request body in the api_step should be able to interpolate the local variables, e.g. "email": "{{ USER }}"

Actual Behavior

The local and global variables are created and look as they should. However when the test runs, it is unable to interpolate the local variables in the request body of the first step.

An error happened while running this step: Unknown variable name USER.

Cursor_and_Edit_Multistep_API_Test_UX_test_-_Login________Datadog (1)

Cursor_and_Edit_Multistep_API_Test_UX_test_-_Login________Datadog

Steps to Reproduce

  1. terraform apply

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions