Terraform Advanced — TF_LOG & Trace

less than 1 minute read

Enable debug logging to understand what Terraform is doing.


Log Levels

# From least to most verbose
export TF_LOG=ERROR    # Only errors
export TF_LOG=WARN     # Warnings + errors
export TF_LOG=INFO     # Informational
export TF_LOG=DEBUG    # Detailed debugging
export TF_LOG=TRACE    # Everything (very verbose)

Log to File

export TF_LOG=TRACE
export TF_LOG_PATH="terraform.log"
terraform plan
# All output goes to terraform.log

Provider-Specific Logging

# Only log the AWS provider at TRACE level
export TF_LOG_PROVIDER=TRACE

# Log core at DEBUG, provider at TRACE
export TF_LOG_CORE=DEBUG
export TF_LOG_PROVIDER=TRACE

Reading Trace Output

Key things to look for in TRACE logs:

1. HTTP requests/responses to cloud APIs
2. "Starting apply" / "Apply complete" markers
3. State read/write operations
4. Provider configuration
5. Error details that don't appear in normal output

Disable Logging

unset TF_LOG
unset TF_LOG_PATH

💡 Production Tip: When filing Terraform bug reports, attach TF_LOG=TRACE output. It’s the first thing maintainers ask for.


What’s Next?

Recover from stuck state locks.

← Debugging Stuck State Lock →

Updated: