- Reproduce unexpected behavior (resources not created, unexpected diffs, confusing errors).
- Provide detailed trace-level logs when filing bug reports with HashiCorp or provider maintainers.
- Audit API calls, provider interactions, and Terraform Core decisions during planning and apply phases.
- You’re investigating non-deterministic or unexplained Terraform behavior.
- A provider or the Terraform binary returns unclear errors.
- You need trace-level evidence to open a bug/issue with maintainers.
- You want to learn how Terraform orchestrates provider calls and state transitions.
| Environment Variable | Purpose | Example |
|---|---|---|
TF_LOG | Enable logging for both Core and providers (global). | export TF_LOG=TRACE |
TF_LOG_CORE | Target logging specifically to Terraform Core (dependency graph, state, planning). | export TF_LOG_CORE=DEBUG |
TF_LOG_PROVIDER | Target logging specifically to provider plugins (AWS, Azure, Kubernetes, etc.). | export TF_LOG_PROVIDER=TRACE |
TF_LOG_PATH | File path to append logs. Only works when a TF_LOG*/TF_LOG variable is set. | export TF_LOG_PATH=terraform.log |
TRACE— most detailed; recommended for bug reports.DEBUG— developer-level detail; slightly less noisy than TRACE.INFO— high-level informational messages.WARN— potential issues worth attention.ERROR— only actual error messages.
STDERR. To save logs to a file, set TF_LOG_PATH in addition to a logging level:
Bash
TF_LOG_PATHdoes nothing by itself — you must setTF_LOG,TF_LOG_CORE, orTF_LOG_PROVIDER.- Logs are appended to the file; rotate or remove the file between runs if you want fresh logs per session.
- Terraform will create the file automatically if it does not exist.
- Log files can become very large at
TRACElevel; prefer targeted runs or rotate logs frequently. - When troubleshooting, prefer
DEBUGorTRACEonly for the shortest time necessary to reduce noise and exposure.
Terraform logs (especially
TRACE-level) can contain sensitive information such as credentials, tokens, or resource attributes. Be careful when saving, sharing, or uploading logs. Redact or sanitize logs before sharing externally.- HashiCorp Terraform environment variables: https://developer.hashicorp.com/terraform/cli/config/environment-variables
Remember these essentials for studying and troubleshooting:
- Key variables:
TF_LOG,TF_LOG_CORE,TF_LOG_PROVIDER,TF_LOG_PATH. - Log level order (most → least verbose):
TRACE,DEBUG,INFO,WARN,ERROR. TF_LOG_PATHonly works when a TF_LOG variable is set.- Logs default to
STDERR; useTF_LOG_PATHto write to a file.
- Terraform CLI environment variables — https://developer.hashicorp.com/terraform/cli/config/environment-variables
- Terraform documentation and provider docs for vendor-specific debugging guidance