Introduction
This guide provides instructions for enabling trace-level logs in HCP Terraform, Terraform Enterprise, and the Terraform CLI. Setting the TF_LOG environment variable to TRACE generates detailed logs that are useful for debugging complex issues with Terraform runs.
Procedure
Follow the method appropriate for your Terraform edition and use case.
Method 1: Enable for a Single Run in HCP Terraform or Terraform Enterprise
This method enables trace logging for a single run directly from the user interface. This feature is available in Terraform Enterprise v202502-2 or later and in all HCP Terraform tiers.
- Navigate to the Overview page of the desired workspace.
- Select New Run to start a new run.
- Configure the Run Name and Run Type as needed.
Expand Additional Planning Options and toggle Enable Debug Logging.
Note: Enabling trace logging this way applies it to the current run only. You must re-enable it for any subsequent runs.
- Select Start Run.
Method 2: Enable via Workspace Variables in HCP Terraform or Terraform Enterprise
This method uses an environment variable within the workspace to enable trace logging for all subsequent runs until the variable is removed.
- Navigate to your workspace's Settings > General page.
In the User Interface section, select Console UI.
- Navigate to Variables and select Add variable.
Create a new Environment Variable with the following values:
- Key:
TF_LOG - Value:
TRACE
- Key:
Start a new run. You can view the detailed logs by selecting View raw log.
After you finish debugging, delete the TF_LOG environment variable from the workspace variables to disable trace logging.
Method 3: Enable for Terraform CLI on Unix, Linux, or macOS
Set the
TF_LOGenvironment variable toTRACEin your terminal.$ export TF_LOG="TRACE"
Run the Terraform operation you wish to debug. Redirect standard output and standard error to a log file using
2>&1and disable ANSI color escape sequences with the-no-colorflag.$ terraform plan -no-color 2>&1 | tee plan.log
After you finish debugging, unset the environment variable.
$ unset TF_LOG
Method 4: Enable for Terraform CLI on Windows
Set the
TF_LOGenvironment variable toTRACEin your PowerShell terminal.$Env:TF_LOG="TRACE"
Run the Terraform operation you wish to debug. Redirect standard output and standard error to a log file and disable ANSI color escape sequences with the
-no-colorflag.$ terraform plan -no-color 2>&1 | Tee-Object -FilePath plan.log
After you finish debugging, remove the environment variable.
$Env:TF_LOG=""
Additional Information
For more details on debugging Terraform, refer to the official documentation on Debugging Terraform.