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() and helper/resource.Test() functions. |
TF_ACC_PROVIDER_HOST : | registry.terraform.io | Set the hostname of the provider under test, such as example.com in the example.com/myorg/myprovider provider source address. This is only required if any TestStep.Config specifies a provider source address, such as in the terraform configuration block required_providers attribute. |
TF_ACC_PROVIDER_NAMESPACE | hashicorp | Set the namespace of the provider under test, such as myorg in the registry.terraform.io/myorg/myprovider provider source address. This is only required if any TestStep.Config specifies a provider source address, such as in the terraform configuration block required_providers attribute. |
TF_ACC_STATE_LINEAGE | N/A | Set to 1 to 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_VERSION is 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.6 or v1.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 each TestStep when the go 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_LOG environment variable used by Terraform CLI while testing. If set, overrides TF_LOG_CORE . Use TF_LOG_CORE and TF_LOG_PROVIDER to configure separate levels for Terraform CLI logging. |
TF_LOG | N/A | Set the log level for the Go standard library log package. If set to any level, sets the TRACE log level for any SDK and provider logs written by terraform-plugin-log . Use the TF_LOG_SDK* and TF_LOG_PROVIDER_* environment variables described in managing log output to decrease or disable SDK and provider logs written by terraform-plugin-log . Use TF_ACC_LOG , TF_LOG_CORE , or TF_LOG_PROVIDER environment variables to set the logging levels used by Terraform CLI while testing. |
TF_LOG_CORE | TF_ACC_LOG | Set the TF_LOG_CORE environment variable used by Terraform CLI logging of graph operations and other core functionality while testing. If TF_ACC_LOG is set, this setting has no effect. Use TF_LOG_PROVIDER to configure a separate level for Terraform CLI logging of external providers while testing (e.g. defined by the TestCase or TestStep type ExternalProviders field). |
TF_LOG_PROVIDER | TF_ACC_LOG | Set the TF_LOG_PROVIDER environment variable used by Terraform CLI logging of external providers while testing (e.g. defined by the TestCase or TestStep type ExternalProviders field). If set, overrides TF_ACC_LOG . Use TF_LOG_CORE to 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_MASK to 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. Use TF_ACC_LOG_PATH to 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-log
based 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 test
process will have its ownlog
package 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.