Skip to main content
This lesson shows how to enable Terraform’s logging to get detailed debugging information when troubleshooting configuration or provider issues. Detailed logs can reveal internal graph transforms, provider attachment, HCL source locations, and diff analysis that help diagnose misconfigurations, provider matching problems, or communication errors.

Minimal demo configuration

Below is the minimal Terraform configuration used for the demo:
Running a normal plan typically produces a concise summary:

When to enable logging

Enable Terraform logging when you need more visibility into what Terraform Core and providers are doing — for example, when:
  • Providers fail to match or load.
  • Resources unexpectedly change or are omitted from the graph.
  • API calls to providers return errors and you need the request/response context.
The most verbose output level is TRACE.

TF_LOG levels

See the official environment variables reference for Terraform logging: Terraform CLI — Environment variables.

Enable verbose logging

  • On macOS / Linux (bash/zsh):
  • On Windows PowerShell:
After enabling TRACE and running terraform plan, you will observe many more internal messages. The excerpts below are representative: they show Terraform’s graph transforms, provider matching, HCL source ranges, and diff decisions.
You will also see resource attachment and HCL source references, which are useful for pinpointing the source file and location for a resource:
Diff determination and change representation are also logged:
These traces make it easier to locate where Terraform is assigning providers, how it builds the resource graph, and why particular resources are created, changed, or left unchanged.
TRACE logs can include sensitive data (like provider tokens, API keys, or resource attributes). Avoid sending raw trace logs to third parties without sanitizing them first.
If you must share logs with HashiCorp or a provider, redact secrets (API keys, tokens, passwords, and any sensitive attributes) before uploading. Consider limiting logs to a file and opening it in a secure editor to mask secrets.

Disable logging when finished

When you’ve captured the necessary information, turn logging off to restore concise output.
  • On macOS / Linux:
  • On Windows PowerShell:
After unsetting, terraform plan returns to the normal concise output:

References

Thanks for following this lesson.

Watch Video