HashiCorp Terraform Associate (004) Question 198
Single answer7c Describe when and how to use verbose loggingA platform engineer runs terraform init in a CI job and it fails while downloading a provider from the Terraform Registry. The job output only shows a generic error message, and the engineer needs more detail to determine whether the problem is a network issue, a registry response issue, or a CLI configuration problem. What is the MOST appropriate way to enable verbose logging for this troubleshooting session?
- A
Set the environment variable
TF_LOG=TRACEbefore runningterraform init, and optionally setTF_LOG_PATHto write the detailed log output to a file. - B
Run
terraform init --verboseto have Terraform print provider download debug logs directly to the terminal. - C
Add
log_level = "TRACE"to the Terraform configuration so all commands use verbose logging until the issue is fixed. - D
Set
TF_INPUT=TRACEbefore runningterraform initso Terraform prompts for additional diagnostic information during initialization.
Show answer and explanation
Correct answer: A
Explanation
When Terraform needs deeper troubleshooting detail, the recommended approach is to enable CLI logging with the TF_LOG environment variable. Valid log levels include TRACE, DEBUG, INFO, WARN, and ERROR, with TRACE producing the most detailed output. For CI pipelines or repeatable investigations, TF_LOG_PATH can write logs to a file for later review. This is especially useful for diagnosing issues during provider installation, backend initialization, plugin communication, or unexpected CLI behavior.
Verbose logging should generally be used only when troubleshooting because it can produce very large output and may include sensitive information in logs. That aligns with Terraform best practices: enable detailed logs temporarily, capture them securely, and disable them afterward. HashiCorp documentation for Terraform CLI environment variables describes TF_LOG and TF_LOG_PATH as the standard mechanism for verbose logging.
- A. Correct.
Correct. Terraform supports verbose logging through the
TF_LOGenvironment variable. Setting it toTRACEenables the most detailed logs, which is appropriate for short-term troubleshooting of issues such as provider installation failures. UsingTF_LOG_PATHis also valid when you want to capture logs in a file instead of relying only on terminal output, which is especially useful in CI environments. - B. Incorrect.
Incorrect. Terraform does not provide a
--verboseflag forterraform initto enable detailed debug logging. This is a common assumption because many CLI tools use such a flag, but Terraform uses environment variables likeTF_LOGfor verbose logging. - C. Incorrect.
Incorrect. Terraform does not support a
log_levelargument in Terraform configuration files for CLI debug logging. Logging is controlled outside the configuration, typically with environment variables, because it is an operational troubleshooting setting rather than part of infrastructure configuration. - D. Incorrect.
Incorrect.
TF_INPUTcontrols whether Terraform prompts for input, typically with values such astrueorfalse. It has nothing to do with logging verbosity. This option reflects a common confusion between Terraform environment variables used for automation and those used for diagnostics.