Hi,
I wanted to create multiple synthetic tests steps with below code using for loop. Below is working code and I want to add one more step and for loop for loop to create other steps
api_steps = [
for steps, summary in local.paths_summary :
{
name = "${summary}"
assertions = [
{
type = "statusCode"
operator = "is"
target = "200"
}
]
request_definition = {
method = "GET"
url = "${var.stage_apisBaseURL}/survey${join("/", tolist([for m in split("/", (replace(replace(steps, "{", "{{"), "}", "}}"))) : startswith(m, "{") && endswith(m, "}") ? upper(m) : m]))}"
}
request_headers = {
Content-Type = "application/json"
X-Cricut-Client = "DD-synthetics"
Authorization = "Bearer ${var.auth_token}"
}
}
]
But I wanted to insert authentication step as part of the loop which is giving me error
api_steps = [
{
name = "Get Authetication Token"
subtype = "http"
assertion = {
type = "statusCode"
operator = "is"
target = 200
}
request_definition = {
method = "POST"
url = "${var.stage_authBaseURL}oauth/token"
body = jsonencode({
"username" : "tester@test.com",
"grant_type" : "password",
"audience" : "https://test.com/public",
"client_id" : "token",
"scope" : "offline_access",
"appName" : "Designer",
"password" : "password"
})
}
request_headers = {
Content-Type = "application/json"
}
extracted_value = {
name = "token"
type = "http_body"
parser = {
type = "json_path"
value = "$.access_token"
}
}
}
,
for steps, summary in local.paths_summary :
{
name = "${summary}"
assertions = [
{
type = "statusCode"
operator = "is"
target = "200"
}
]
request_definition = {
method = "GET"
url = "${var.stage_apisBaseURL}/survey${join("/", tolist([for m in split("/", (replace(replace(steps, "{", "{{"), "}", "}}"))) : startswith(m, "{") && endswith(m, "}") ? upper(m) : m]))}"
}
request_headers = {
Content-Type = "application/json"
X-Cricut-Client = "DD-synthetics"
Authorization = "Bearer ${var.auth_token}"
}
}
]
# Optional
variable "api_steps" {
description = "Steps for multistep api tests"
type = list(any)
default = null
}
In steps the URL are reading from Swagger JSON file
Any solutions appreciated ??