.tftest.hcl file

A test file for terraform test, written in HCL, containing run blocks that exercise a module and assert blocks that check the results.

In more detail

Test files usually live in a tests directory beside the module. Each run block can set command = plan to check a plan without creating anything, or apply to build real resources and check their outputs.

Example

run "names_are_prefixed" {
  command = plan
  assert {
    condition     = output.summary != ""
    error_message = "summary must not be empty"
  }
}

Related terms

Taught in

References

Certification courses