Desperate need of references of terraform test article

I am really struggling reading through this article terraform test and trying not to get frustrated.
This snippet

equal “scheme” {
description = “default scheme is https”
got = local.api_url_parts.scheme
want = “https”
}

check “port_number” {
description = “default port number is 8080”
condition = can(regex(“:8080$”, local.api_url_parts.authority))
}

What is check? What is equal? Where is it coming from? Other than in this page, I couldn’t find any references in the official hashicorp docs about those 2 “things”.

As it says on the page you linked:

# equal and check blocks serve as the test assertions.
# the labels on these blocks are unique identifiers for
# the assertions, to allow more easily tracking changes
# in success between runs.

They are just part of the test_assertions resource, which is based on a provider that @apparentlymart created - I think the documentation from that provider is still probably useful: Terraform Registry

Basically check and equals are two ways of making assertions that have to pass for the test to be seen as passing. The equals is a bit simpler, just checking the value of got is the same as the value of want, while check has a condition that can be more complex.

1 Like

Hi @stuart-c!

This is broadly correct but I just want to note that the provider used by terraform test is terraform.io/builtin/test rather than apparentlymart/testing.

The two have a similar purpose but the Terraform team decided to embed a subset of my original provider into Terraform for the sake of this experiment, primarily because it made it easier to ship them both together and evolve them together based on initial feedback.

The design of the equal and check blocks is similar between the two though, so indeed the information I wrote in my own provider’s documentation might be useful extra context for what’s going on in the one built in to the testing experiment.

1 Like