Skip to main content
This guide explains how Terraform logging works, how to enable and collect logs, and how to use logs to troubleshoot provider and API issues. It focuses on the two environment variables Terraform uses for logging (TF_LOG and TF_LOG_PATH), how to interpret common log entries, and best practices for secure log handling and centralized ingestion.

Key environment variables

Terraform logging is configured with environment variables:
  • TF_LOG — sets the logging verbosity level Terraform will emit.
  • TF_LOG_PATH — when set, Terraform writes logs to the specified file instead of streaming verbose logs to the console.
Example — enable the most verbose logging and persist it to a file:
If you run Terraform on an Azure VM or build agent, install the Azure Monitor Agent to collect the TF_LOG file and send it to a Log Analytics workspace. This enables centralized querying, filtering, and analysis of Terraform logs. See: https://learn.microsoft.com/azure/azure-monitor/agents/azure-monitor-agent
Terraform logs at DEBUG or TRACE levels can contain sensitive data such as secrets or API tokens. Treat files created via TF_LOG_PATH as sensitive: restrict access, redact before sharing, and rotate credentials if exposed.

TF_LOG levels

Terraform supports these logging levels (from least to most verbose). Setting a level will include that level and all higher-severity messages. Recommendation: use DEBUG for typical troubleshooting. Reserve TRACE for deep investigations, and avoid those levels for routine CI runs unless necessary.

Example Terraform configuration

The following compact example is used throughout this guide. It provisions an Azure resource group and a storage account. A local-exec provisioner demonstrates how Terrafrom can execute local commands (note: provisioners and writing secrets to disk have security implications).
Note: the azurerm provider version and attribute availability can vary. To construct a real connection string, you may need to use provider attributes, data sources, or by retrieving account keys. Avoid writing secrets to disk where possible.

Running Terraform with logging enabled

Set the environment variables in your terminal or CI agent before running Terraform commands. Example:
Behavior:
  • When TF_LOG is set and TF_LOG_PATH is unset, verbose logs stream to the console.
  • When TF_LOG_PATH is set, detailed logs are written to the file and Terraform’s console output remains the normal, succinct Terraform summary (the plan/apply text remains readable).
  • For CI systems, prefer writing logs to a file and ingesting that file into your centralized logging.

Inspecting and filtering the log file

Search and filter the log file to focus on provider API calls or errors. For example, to see provider HTTP GET requests:
Representative output:
These entries show provider calls to Azure Resource Manager and storage endpoints. Reviewing these HTTP requests and their timestamps helps diagnose issues like authentication failures, rate limits, incorrect API versions, or missing resources.

Sample log snippets

A provider plugin error and subsequent plugin exit may appear like this (cleaned and representative):
A normal terraform plan run (console output remains user-friendly even when TF_LOG_PATH is set):

Reducing verbosity

If TRACE or DEBUG is too noisy, reduce the level:
Guidance:
  • Use INFO or WARN for routine runs.
  • Use DEBUG to investigate provider-specific issues.
  • Use TRACE only when troubleshooting deep internals or when requested by provider maintainers.

Best practices for secure logging and centralized analysis

  • Treat TF_LOG_PATH output as sensitive data. Limit permissions and encryption-at-rest where possible.
  • Redact or scrub logs before sharing externally or attaching to tickets.
  • Rotate credentials if they may have been exposed in logs.
  • In production pipelines, send logs to a centralized logging system (e.g., Azure Log Analytics, Splunk, Elastic) and apply retention, access controls, and alerting.
  • For Azure-specific ingestion, use the Azure Monitor Agent to forward log files to a Log Analytics workspace for query and correlation.

Quick reference

Summary

  • Control Terraform logging with TF_LOG and persist logs with TF_LOG_PATH.
  • DEBUG and TRACE reveal provider and API interactions—very useful for troubleshooting, but they can expose secrets.
  • Centralize TF_LOG outputs with logging agents (Azure Monitor Agent → Log Analytics) for better analysis and retention.
  • Inspect provider HTTP calls in logs to understand what Terraform requested and how the cloud provider responded.

Watch Video