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?
- A.terraform validate -test, which reads assertions from variables.tf
- B.terraform test, which runs files ending in .tftest.hcl containing run blocks with assert conditions
- C.terraform console -batch, which compares outputs with expected values
- 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
- Skipping refresh during plan
- Local state backup file
- Default CLI workspace cannot be deleted
- Local execution mode in HCP Terraform
- Self-hosted agents for private networks
- Run triggers between workspaces
- Health assessments for drift detection
- Dynamic provider credentials with OIDC
- terraform_data triggers_replace argument
- Provisioners as a last resort
- Lock file hashes for multiple platforms