#2001·opentofu

Ability to omit or template `error_message` in test assertions

Author: wyardleyCreated Sep 19, 2024Updated Sep 24, 2026
Labelsenhancementaccepted

OpenTofu Version

bash
OpenTofu v1.8.2
on darwin_arm64

Use Cases

For large tests, it's annoying to have to write in error_message when the response will already give pretty useful context. It would be nice to be able to have a boilerplate template (attribute %s doesn't match %s) and / or omit the error_message for a default.

hcl
run "basic" {
  assert {
    condition     = google_compute_target_http_proxy.http_cdn_backend_target_proxy.name == "test-me-http-target-proxy"
    error_message = "Incorrect target proxy name."
  }
}

In this example, the error message doesn't really provide any useful information beyond what the builtin error message already tells us; it's just another block requiring space and needing to be filled up.

│ Error: Test assertion failed
│ 
│   on main.tftest.hcl line 32, in run "basic":
│   32:     condition = google_storage_bucket.cdn_bucket.name == "test-me-foo-estproject"
│     ├────────────────
│     │ google_storage_bucket.cdn_bucket.name is "test-me-foo-testproject"
│ 
│ Incorrect bucket name.

Attempted Solutions

n/a

Proposal

Can submit this request upstream if you think this needs to match Terraform's behavior exactly.

References

No response