NashTech Blog

Terraform detailed logging for effective troubleshooting

Table of Contents
kanban, work, office-6900750.jpg
man holding teacup infront of laptop on top of table inside the room
Photo by Andrea Piacquadio on Pexels.com

fff : https://developer.hashicorp.com/terraform/internals/debugging

 

Terraform simplifies infrastructure management through its declarative configuration language. Managing complex infrastructures can lead to errors that are challenging to diagnose. In such cases, Terraform’s detailed logging can be a lifesaver. In this guide, we’ll explore how to leverage Terraform’s logging capabilities for effective troubleshooting.

Enabling Detailed Logging: Terraform provides detailed logs that can be enabled by setting the TF_LOG environment variable to any value. This setting causes detailed logs to appear on stderr, providing valuable insights into Terraform’s internal operations.

Controlling Log Verbosity: You can set TF_LOG to one of the log levels: TRACE, DEBUG, INFO, WARN, or ERROR, in order of decreasing verbosity. This allows you to control the amount of detail in the logs based on your troubleshooting needs.

Using JSON Formatting: Setting TF_LOG to JSON outputs logs at the TRACE level or higher, using a parseable JSON encoding as the formatting. JSON encoding of files is not a stable interface and may change without warning .

Enabling Logging for Terraform and Providers: Logging can be enabled separately for Terraform itself and the provider plugins using the TF_LOG_CORE or TF_LOG_PROVIDER environment variables. These variables take the same level arguments as TF_LOG but only activate a subset of the logs, making it easier to focus on specific components.

Persisting Log Output: To persist logged output, you can set the TF_LOG_PATH environment variable to force the log to always be appended to a specific file when logging is enabled. However, even when TF_LOG_PATH is set, TF_LOG must also be set for any logging to be enabled.

If you encounter a bug with Terraform, including the detailed log can greatly help in diagnosing and resolving the issue. 

 

 

Picture of Saumya

Saumya

Leave a Comment

Your email address will not be published. Required fields are marked *

Suggested Article

Scroll to Top