Skip to main content
In this article, we explore how to enable and use debugging in Terraform to effectively troubleshoot and resolve issues. When Terraform errors occur, the first step is to review the log output. While Terraform’s error messages during provisioning are helpful, sometimes you need to dive deeper for an internal view. Terraform allows you to increase the debugging output by setting the environment variable TF_LOG to one of the available log level values. The supported log levels are: info, warning, error, debug, and trace—with trace providing the most detailed output.
For the most verbose logging, use TF_LOG=TRACE. This is particularly useful when facing complex issues that require insight into Terraform’s inner workings.

Enabling Debugging

To enable the trace log level, set the TF_LOG environment variable as follows:
After setting this variable, running any Terraform command will produce detailed logs corresponding to the selected verbosity level. For example, a Terraform plan run with TF_LOG set to TRACE might output hundreds or even thousands of lines, capturing every internal operation performed by Terraform plugins. Below is an example output from running terraform plan with elevated logging:

Logging to a File

If you want to persist these logs to a file for later review or to include them in bug reports, set the environment variable TF_LOG_PATH with the desired file path as shown below:
All generated logs will then be recorded in the specified file. To quickly inspect the beginning of your log file, you can use a command like:
An example snippet from the log file might look like this:

Disabling Debug Logs

To completely disable the debugging output, simply unset the environment variables:
Remember to unset these variables when you no longer need detailed logs, as verbose logging can expose sensitive information and impact performance.

That concludes our discussion on debugging Terraform. Up next, you’ll have the opportunity to practice Terraform tainting and explore additional debugging techniques through interactive exercises. For more information, visit the Terraform Documentation for an in-depth look at other available commands and best practices.

Watch Video

Practice Lab