http_assertion

Validate HTTP responses.

HTTP assertions can be used to validate HTTP responses.

Example

resource "http_assertion" "my_assertion" {
  source = "status_code"
  comparison = "equals"
  target = "200"
}

Inputs

  • source – location of the response value.
  • comparison – comparison operation to perform on the source value.
  • target – expected source value.
  • property – property name of the source (json_body and header sources only).

Sources

  • status_code — response status code.
  • header — response header.
  • body — response body.
  • json_body — JSON response body.

Comparisons

  • less_than — source value is less than target value.
  • less_than_or_equal — source value is less than target value, or equals target value.
  • greater_than &msash; source value is greater than target value.
  • greater_than_or_equal — source value is greater than target value, or equals target value.
  • is_empty — source value is empty or null.
  • is_not_empty — source value is not empty.
  • equals — source value equals target value (string comparison).
  • does_not_equal — source value does not equal target value (string comparison).
  • contains — source value contains target value (string comparison).
  • does_not_contain — source value does not contain target value (string comparison).
  • has_key — test whether JSON dictionary located at property contains key specified in target. (json_body only.
  • has_value — JSON array located at property contains item specified in target.
  • equals_number — source value equals target value (json_body only; numeric comparison, 1 == 1.00).
  • is_null — JSON property is null (json_body only).
  • is_a_number — JSON property is a number (json_body only).

Properties

Property is an additional piece of information that some value sources require. Property is optional for body and status_code sources.

.

header source uses property to find HTTP header for comparison:

source = "header"
target = "Content-Type"

json_body source uses property to find attribute within JSON object:

source = "json_body"
target = "data.key[0]"

Outputs

  • id - resource ID.