HashiCorp Terraform Associate (004) Question 195
Single answer7c Describe when and how to use verbose loggingA platform engineer runs terraform init in a CI job and it intermittently fails while downloading a provider from the Terraform Registry. The standard output only shows a generic error, and the engineer needs more detail to determine whether the problem is caused by Terraform CLI behavior, network access, or the provider installation process. What is the best way to collect detailed diagnostic information for this troubleshooting session without changing the Terraform configuration?
- A
Set the
TF_LOG=TRACEenvironment variable for the command run, and optionally setTF_LOG_PATHto write the verbose logs to a file for later review. - B
Add
verbose = trueinside theterraformblock in the root module so Terraform prints additional debug details during initialization. - C
Run
terraform init -verboseso the CLI outputs provider download and registry API debug details. - D
Set
TF_VAR_LOG=TRACEbefore runningterraform initso Terraform enables detailed logging through an input variable.
Show answer and explanation
Correct answer: A
Explanation
Verbose logging in Terraform is primarily used for troubleshooting when normal command output does not provide enough detail, such as diagnosing provider installation failures, plugin startup issues, backend communication problems, or unexpected CLI behavior. The standard mechanism is to set the TF_LOG environment variable to a log level such as TRACE, DEBUG, INFO, WARN, or ERROR, with TRACE being the most detailed. To capture logs persistently, especially in automation or CI/CD pipelines, you can also set TF_LOG_PATH so Terraform writes logs to a file. This is preferable to modifying Terraform configuration just to troubleshoot a transient issue. HashiCorp documentation for Terraform CLI environment variables and debugging guidance describes TF_LOG and TF_LOG_PATH as the supported way to enable verbose diagnostic output.
- A. Correct.
Correct. Terraform CLI supports verbose logging through the
TF_LOGenvironment variable. Setting it to a level such asTRACEenables very detailed logs that can help diagnose initialization, provider installation, plugin, and network-related issues. UsingTF_LOG_PATHis also a valid best practice when you want to persist logs from a CI run or share them for troubleshooting. This approach does not require any configuration changes in the Terraform code. - B. Incorrect.
Incorrect. There is no supported
verbose = trueargument in theterraformblock for enabling CLI debug logging. A candidate might choose this because many tools expose logging settings in configuration files, but Terraform verbose logging is controlled through environment variables, not through HCL configuration. - C. Incorrect.
Incorrect. Terraform does not provide a general
-verboseflag forterraform initto enable debug logging. This is a common misconception because many CLIs use such flags, but Terraform usesTF_LOGfor detailed internal logs. - D. Incorrect.
Incorrect.
TF_VAR_environment variables are used to pass values into Terraform input variables, not to control Terraform CLI behavior. Naming a variableLOGwould only populate an input variable calledlogif one existed; it would not enable diagnostic logging.