
Quick tip: start with
TF_LOG=ERROR or TF_LOG=WARN for targeted problems. Increase to DEBUG or TRACE only when you need detailed provider or RPC-level traces, because higher levels produce a lot of noise.How to enable debug logs
Use theTF_LOG environment variable to set the verbosity and TF_LOG_PATH to write logs to a file instead of flooding the console.
Bash (Linux / macOS):
TF_LOG levels:
TRACE— very verbose; includes HTTP requests and detailed internals.DEBUG— developer-level debug information.INFO— general progress and informational messages.WARN— warnings about potential issues.ERROR— only errors.
TF_LOG_PATH and let the logs stream to stdout. To keep CI logs manageable, always set TF_LOG_PATH and rotate or archive logs.
Practical capture & search workflow
- Reproduce the failing command (e.g.,
terraform planorterraform apply) withTF_LOGset. - Save logs to
TF_LOG_PATHso you can inspect and share selectively. - Search for high-level markers first:
ERRORandWARNentries- Provider response payloads or HTTP status codes
- State-related messages such as locks or conflicts
- If necessary, increase to
TRACEand re-run only the failing action to limit volume.
Common error sources and where to look
- Configuration syntax or validation errors — often shown directly in Terraform CLI output (check
terraform validate). - Provider authentication/authorization failures — inspect provider init/auth sections in logs.
- Remote state and lock conflicts — look for state backend messages and lock acquisition attempts.
- Provider or API errors —
TRACE/DEBUGshow HTTP responses and request payloads for APIs. - Resource dependencies and lifecycle issues — check planning output and graph-related messages.
- Can you reproduce the failure locally?
- Did you validate the configuration (
terraform validate)? - Is provider authentication current (tokens, service principal, credentials)?
- Is the remote state reachable and unlocked?
Systematic debugging steps
- Reproduce with the minimal command and configuration.
- Run
terraform validateandterraform planwithout debug first — many issues are visible here. - Enable
TF_LOG=DEBUGand setTF_LOG_PATHto capture logs. - Inspect
terraform.log: start withERROR/WARN, then expand to provider-specific sections. - If you find sensitive data in the logs, redact before sharing with others or support.
- If needed, increase to
TRACEfor deeper protocol-level details and provider internals.
References and further reading
- Official Terraform logging docs: https://www.terraform.io/docs/cli/config/config.html#logging
- Provider troubleshooting: https://www.terraform.io/docs/extend/providers.html
- State and backends: https://www.terraform.io/docs/state/index.html
Warning: Terraform debug logs can contain sensitive data (API tokens, secrets, or resource attributes). Avoid publishing raw logs publicly. Redact secrets before sharing with colleagues or support.