There are a few ways to enable trace-level logs in Terraform, depending on what product is being used.
Generally, to capture a trace log, set the environment variable TF_LOG to TRACE. Refer to the details below for specific steps for your Terraform product:
Terraform Enterprise and HCP Terraform
Via Workspace Run UI
In Terraform Enterprise (v202502-2 or later) or HCP Terraform navigate to the Overview page of the workspace.
- Start a new run by clicking New Run.
- Configure Run Name and Run Type as desired.
- Expand Additional Planning Options > Toggle Enable Debug Logging.
- NOTE: Enabling trace logging this way enables it for this run only and will need enabled for any follow up runs.
- Start Run.
Via Workspace Variables
In Terraform Enterprise or HCP Terraform, perform these steps in your Workspace:
- Navigate to Settings > General > User Interface, and select "Console UI"
- Navigate to Variables > Workspace Variables, and add a new variable with "Environment" as category,
TF_LOGas key, andTRACEas value - Start a new run
- Click on "View raw log"
Once you are done debugging, you can simply delete the variable from the Terraform Enterprise UI.
Terraform CLI
Unix/Linux & macOS
In your Linux/macOS terminal, run the following commands:
Set the TF_LOG environment variable:
export TF_LOG="TRACE"Run the Terraform operation that you wish to debug, e.g., init, plan, apply, or import. Make sure you capture
stdoutandstderrwith2>&1, and disable ANSI color escape sequences with-no-color:terraform plan -no-color 2>&1 | tee plan.log
Once you are done debugging, remove the variable by running: unset TF_LOG
Windows
In your PowerShell terminal, run the following commands:
Set the TF_LOG environment variable:
$Env:TF_LOG="TRACE"Run the Terraform operation that you wish to debug, e.g., init, plan, apply, or import. Make sure you capture
stdoutandstderrwith2>&1, and disable ANSI color escape sequences with-no-color:terraform plan -no-color 2>&1 | Tee-Object -FilePath plan.log
Once you are done debugging, remove the variable by running: $Env:TF_LOG=""