HashiCorp Terraform Associate (004) exam dumps

HashiCorp Terraform Associate (004) practice question 197 of 223

Terraform Associate 004. Associate level, HashiCorp. Free question with the correct answer and a full explanation.

HashiCorp Terraform Associate (004) Question 197

Single answer7c Describe when and how to use verbose logging

A platform engineer runs terraform init in a CI job and it fails intermittently while downloading a provider from the registry. The standard error output only shows a generic network error, and the engineer needs more detail to determine whether the failure is caused by Terraform core, the provider installation process, or the remote service response. What is the best way to enable verbose logging for this troubleshooting session without changing the Terraform configuration itself?

  1. A

    Set the TF_LOG environment variable to a level such as DEBUG or TRACE before running terraform init, and optionally set TF_LOG_PATH to write the logs to a file.

  2. B

    Add log_level = "TRACE" to the root module so Terraform will emit detailed logs for all commands.

  3. C

    Run terraform init -verbose to force Terraform to print internal plugin and HTTP logs to the console.

  4. D

    Set TF_VAR_LOG=TRACE so Terraform treats logging as an input variable and increases output detail.

Show answer and explanation

Correct answer: A

Explanation

The best practice for Terraform verbose logging is to enable it only when troubleshooting because detailed logs can be noisy and may include sensitive information from provider interactions, request metadata, or configuration processing. In a real-world CI failure during terraform init, the most appropriate action is to set TF_LOG to a suitable level such as DEBUG or TRACE for that session. If log retention is needed, TF_LOG_PATH writes the output to a file. This approach helps distinguish whether an issue originates in Terraform core, provider/plugin installation, or an external registry/service response without modifying the Terraform configuration. HashiCorp documentation for Terraform CLI environment variables describes TF_LOG and TF_LOG_PATH as the standard mechanism for enabling detailed logs.

  • A. Correct.

    Correct. Terraform verbose logging is typically enabled with the TF_LOG environment variable. Valid levels include values such as TRACE, DEBUG, INFO, WARN, ERROR, and OFF. For troubleshooting intermittent initialization, provider installation, registry communication, or other internal behavior, setting TF_LOG=DEBUG or TF_LOG=TRACE before running the command is the standard approach. TF_LOG_PATH can also be set to persist logs to a file, which is especially useful in CI systems where console output may be truncated or hard to review later.

  • B. Incorrect.

    Incorrect. Terraform does not support a log_level argument inside the root module or Terraform configuration files for enabling CLI debug logs. Logging is controlled through environment variables, not through HCL configuration. A candidate might choose this because many tools allow logging configuration in project files, but Terraform CLI diagnostic logging is external to the configuration.

  • C. Incorrect.

    Incorrect. There is no general -verbose flag for terraform init that enables Terraform's internal diagnostic logging in this way. Terraform uses the TF_LOG mechanism instead. This distractor is plausible because many CLI tools use --verbose or -v, but that is not how Terraform Associate-level troubleshooting is performed for detailed internal logs.

  • D. Incorrect.

    Incorrect. TF_VAR_* environment variables are used to pass input variable values into Terraform, not to configure CLI logging behavior. TF_VAR_LOG would only map to an input variable named log if one existed in the configuration. It would not increase diagnostic output. This reflects a common misunderstanding between Terraform environment variables for runtime behavior and those for variable injection.

Timed practice exam

Take a HashiCorp Terraform Associate (004) practice test under exam conditions

70 questions in 60 minutes, drawn from this bank, with a score report and a per-question review when you finish.

Start timed exam