Terraform
Acceptance Testing: Environment Variables
A number of environment variables are available to control aspects of acceptance test execution.
| Environment Variable Name | Default | Description | 
|---|---|---|
| TF_ACC | N/A | Set to any value to enable acceptance testing via the helper/resource.ParallelTest()andhelper/resource.Test()functions. | 
| TF_ACC_PROVIDER_HOST: | registry.terraform.io | Set the hostname of the provider under test, such as example.comin theexample.com/myorg/myproviderprovider source address. This is only required if anyTestStep.Configspecifies a provider source address, such as in theterraformconfiguration blockrequired_providersattribute. | 
| TF_ACC_PROVIDER_NAMESPACE | hashicorp | Set the namespace of the provider under test, such as myorgin theregistry.terraform.io/myorg/myproviderprovider source address. This is only required if anyTestStep.Configspecifies a provider source address, such as in theterraformconfiguration blockrequired_providersattribute. | 
| TF_ACC_STATE_LINEAGE | N/A | Set to 1to enable state lineage debug logs, which are normally suppressed during acceptance testing. | 
| TF_ACC_TEMP_DIR | Operating system specific via os.TempDir() | Set a temporary directory used for testing files and installing Terraform CLI, if installation is required. | 
| TF_ACC_TERRAFORM_PATH | N/A | Set the path to a Terraform CLI binary on the local filesystem to be used during testing. It must be executable. If not found and TF_ACC_TERRAFORM_VERSIONis not set, an error is returned. | 
| TF_ACC_TERRAFORM_VERSION | N/A | Set the exact version of Terraform CLI to automatically install into TF_ACC_TEMP_DIR. For example,1.1.6orv1.0.11. | 
| TF_ACC_PERSIST_WORKING_DIR | N/A | Set to any value to enable persisting the working directory and the files generated during execution of each TestStep. The location of each directory is written to the test output for eachTestStepwhen thego test -v(verbose) flag is provided. | 
Logging Environment Variables
A number of environment variables available to control logging aspects during acceptance test execution. Some of these modify or replace the production behaviors defined in managing provider log output and debugging Terraform.
Logging Levels
| Environment Variable Name | Default | Description | 
|---|---|---|
| TF_ACC_LOG | N/A | Set the TF_LOGenvironment variable used by Terraform CLI while testing. If set, overridesTF_LOG_CORE. UseTF_LOG_COREandTF_LOG_PROVIDERto configure separate levels for Terraform CLI logging. | 
| TF_LOG | N/A | Set the log level for the Go standard library logpackage. If set to any level, sets theTRACElog level for any SDK and provider logs written byterraform-plugin-log. Use theTF_LOG_SDK*andTF_LOG_PROVIDER_*environment variables described in managing log output to decrease or disable SDK and provider logs written byterraform-plugin-log. UseTF_ACC_LOG,TF_LOG_CORE, orTF_LOG_PROVIDERenvironment variables to set the logging levels used by Terraform CLI while testing. | 
| TF_LOG_CORE | TF_ACC_LOG | Set the TF_LOG_COREenvironment variable used by Terraform CLI logging of graph operations and other core functionality while testing. IfTF_ACC_LOGis set, this setting has no effect. UseTF_LOG_PROVIDERto configure a separate level for Terraform CLI logging of external providers while testing (e.g. defined by theTestCaseorTestSteptypeExternalProvidersfield). | 
| TF_LOG_PROVIDER | TF_ACC_LOG | Set the TF_LOG_PROVIDERenvironment variable used by Terraform CLI logging of external providers while testing (e.g. defined by theTestCaseorTestSteptypeExternalProvidersfield). If set, overridesTF_ACC_LOG. UseTF_LOG_COREto configure a separate level for Terraform CLI logging of graph operations and other core functionality while testing. | 
Logging Output
By default, there is no logging output when running the go test command. Use one of the below environment variables to output logs to the local filesystem or use the go test command -v (verbose) flag to view logging without writing file(s).
| Environment Variable Name | Default | Description | 
|---|---|---|
| TF_ACC_LOG_PATH | N/A | Set a file path for all logs during testing. Use TF_LOG_PATH_MASKto configure individual log files per test. | 
| TF_LOG_PATH_MASK | N/A | Set a file path containing the string %s, which is replaced with the test name, to write a separate log file per test. UseTF_ACC_LOG_PATHto configure a single log file for all tests. | 
The logs associated with each test can output across incorrect files as each
new test starts if the provider is using the Go standard library log
package for logging, acceptance testing that uses
helper/resource.ParallelTest(),
and TF_LOG_PATH_MASK. To resolve this issue, choose one of the following
approaches:
- Use terraform-plugin-logbased logging. Each logger will be correctly associated with each test name output.
- Wrap testing execution so that each test is individually executed with go test. Since eachgo testprocess will have its ownlogpackage output handling,logging will be correctly associated with each test name output.
- Replace helper/resource.ParallelTest()withhelper/resource.Test()and ensure(*testing.T).Parallel()is not called in tests. This serializes all testing so each test will be associated with each test name output.