CertKeen

Terraform Associate (004) · Free practice question 11 of 12

Running tests with terraform test

Oakhaven Software wants to write automated tests for a module that run a plan with sample input values and assert on the results. Which feature does Terraform provide for this?

  1. A.terraform validate -test, which reads assertions from variables.tf
  2. B.terraform test, which runs files ending in .tftest.hcl containing run blocks with assert conditions
  3. C.terraform console -batch, which compares outputs with expected values
  4. D.terraform fmt -check, which verifies module outputs
Show answer and explanation

Correct answer: B. terraform test, which runs files ending in .tftest.hcl containing run blocks with assert conditions

Why: The terraform test command discovers test files ending in .tftest.hcl and executes their run blocks, each of which can run a plan or apply and evaluate assert conditions. validate has no test mode, console is an interactive expression evaluator, and fmt -check only checks formatting.

More free Terraform Associate (004) questions