HashiCorp Terraform Associate (004) Question 194
Single answer7c Describe when and how to use verbose loggingA platform engineer runs terraform plan in a CI job and gets a generic provider-related error that does not appear when using the same configuration locally. The engineer needs more detail to troubleshoot the issue, but the CI logs must remain manageable and should not expose more information than necessary. Which action is the most appropriate way to enable verbose logging for this troubleshooting session?
- A
Set the
TF_LOGenvironment variable to an appropriate level such asDEBUGorTRACEonly for the failing run, and optionally direct output to a file withTF_LOG_PATH. - B
Add
verbose_logging = trueto the Terraform configuration so all future plans and applies automatically include detailed logs. - C
Run
terraform plan -verboseto increase logging only for this command without changing environment variables. - D
Set
TF_VAR_LOG=DEBUGin the CI pipeline so Terraform and all providers emit detailed diagnostic logs.
Show answer and explanation
Correct answer: A
Explanation
The correct approach is to use Terraform's logging environment variables for temporary, focused troubleshooting. TF_LOG enables verbose logs for the Terraform CLI and can help diagnose issues involving provider interactions, plugin startup, backend communication, and other internal operations. In practice, engineers should enable logging only for the failing session because verbose logs, especially at TRACE, can be very large and may include sensitive or low-level details. When troubleshooting in CI, TF_LOG_PATH is useful to capture logs in a file rather than flooding the console output. This aligns with HashiCorp guidance for debugging Terraform behavior using environment variables rather than configuration blocks or unsupported command flags.
- A. Correct.
Correct. Terraform supports verbose logging through the
TF_LOGenvironment variable, with levels such asTRACE,DEBUG,INFO,WARN, andERROR. For targeted troubleshooting, best practice is to enable it only when needed, especially in CI where logs can become noisy or contain sensitive details.TF_LOG_PATHcan be used to write logs to a file instead of standard output, which helps keep pipeline output manageable. - B. Incorrect.
Incorrect. There is no Terraform configuration argument named
verbose_loggingthat enables CLI debug logging globally. Verbose logging is controlled through environment variables such asTF_LOG, not through a setting in.tffiles. - C. Incorrect.
Incorrect. Terraform does not provide a
-verboseflag onterraform planfor CLI debug logging. A candidate might choose this because many command-line tools use similar flags, but Terraform relies on environment variables for this behavior. - D. Incorrect.
Incorrect.
TF_VAR_environment variables are used to pass input variable values into Terraform, not to control Terraform CLI logging. This option reflects a common confusion between Terraform input variables and Terraform's own operational environment variables.