Documentation Index
Fetch the complete documentation index at: https://mintlify.com/hashicorp/terraform/llms.txt
Use this file to discover all available pages before exploring further.
Command: test
Theterraform test command executes automated integration tests against the current Terraform configuration.
Usage
.tftest.hcl files within the current configuration and testing directories. Terraform will then execute the testing run blocks within any testing files in order, and verify conditional checks and assertions against the created infrastructure.
Options
-
-cloud-run=source- If specified, Terraform will execute this test run remotely using HCP Terraform or Terraform Enterprise. You must specify the source of a module registered in a private module registry as the argument to this flag. This allows Terraform to associate the cloud run with the correct HCP Terraform or Terraform Enterprise module and organization. -
-filter=testfile- If specified, Terraform will only execute the test files specified by this flag. You can use this option multiple times to execute more than one test file. -
-json- If specified, machine readable output will be printed in JSON format. -
-junit-xml=path- Saves a test report in JUnit XML format to the specified file. This is currently incompatible with remote test execution using the-cloud-runoption. The file path must be relative or absolute. -
-no-color- If specified, output won’t contain any color. -
-parallelism=n- Limit the number of concurrent operations within the plan/apply operation of a test run. Defaults to 10. -
-test-directory=path- Set the Terraform test directory. Defaults to"tests". -
-var 'NAME=VALUE'- Set a value for one of the input variables in the root module of the configuration. Use this option multiple times to set more than one variable. -
-var-file=FILENAME- Load variable values from the given file, in addition to the default filesterraform.tfvarsand*.auto.tfvars. Use this option multiple times to include more than one variables file. -
-verbose- Print the plan or state for each test run block as it executes.
Test File Structure
Test files use the.tftest.hcl extension and contain one or more run blocks. Each run block represents a test case.
Example test file:
Test Directory
By default, Terraform looks for test files in atests/ directory relative to your configuration. You can customize this location using the -test-directory flag.