Skip to content

004 · Domain 7: Maintain infrastructure with Terraform · 12% of the exam

Task 7.3: Describe when and how to use verbose logging

TF_LOG levels from TRACE to ERROR, TF_LOG_CORE and TF_LOG_PROVIDER, writing logs to a file with TF_LOG_PATH, and what to include in a crash or bug report.

Study it

Sample questions

Try each one before opening the answer. Every option is explained, with the HashiCorp documentation page that proves it.

Question 1 · choose 1

A provider returns a vague error, and support asks for the most detailed Terraform log possible. Which setting gives the most verbose output?

  1. ATF_LOG=TRACE
  2. BTF_LOG=DEBUG
  3. CTF_LOG=ERROR
  4. DTF_LOG=VERBOSE
Show the answer and why
  • ATF_LOG=TRACE

    Correct

    TF_LOG accepts TRACE, DEBUG, INFO, WARN and ERROR in decreasing order of verbosity.

  • BTF_LOG=DEBUG

    Incorrect

    DEBUG is one level less verbose than TRACE.

  • CTF_LOG=ERROR

    Incorrect

    ERROR is the least verbose level.

  • DTF_LOG=VERBOSE

    Incorrect

    VERBOSE is not a log level.

TRACE, DEBUG, INFO, WARN, ERROR: most to least verbose.

Question 2 · choose 2

A pipeline sets TF_LOG_PATH=./terraform.log so that logs are kept as a build artifact, but the file never appears. Which two statements explain or fix this? (Choose TWO.)

  1. ATF_LOG must also be set, because TF_LOG_PATH alone does not enable logging
  2. BTF_LOG_PATH works only with the JSON log format
  3. CWith TF_LOG set, the log is appended to that file
  4. DTF_LOG_PATH must point to an existing directory, not to a file name
  5. ELogs are written to the path only when the run fails
Show the answer and why
  • ATF_LOG must also be set, because TF_LOG_PATH alone does not enable logging

    Correct

    Even when TF_LOG_PATH is set, TF_LOG must be set for any logging to be enabled.

  • BTF_LOG_PATH works only with the JSON log format

    Incorrect

    Any log level can be written to the file.

  • CWith TF_LOG set, the log is appended to that file

    Correct

    TF_LOG_PATH forces the log to be appended to the given file whenever logging is enabled.

  • DTF_LOG_PATH must point to an existing directory, not to a file name

    Incorrect

    It names the file to write to.

  • ELogs are written to the path only when the run fails

    Incorrect

    Logs are written whenever logging is enabled.

TF_LOG turns logging on; TF_LOG_PATH decides where it goes.

Question 3 · choose 1

A developer wants a debug log for one terraform plan run only, without leaving logging switched on in the shell afterward. On a Unix shell, which approach does this?

  1. APrefix it: TF_LOG=DEBUG terraform plan
  2. BRun terraform plan -log=debug
  3. CAdd log_level = "debug" to the terraform block
  4. DRun terraform init -debug before the plan
Show the answer and why
  • APrefix it: TF_LOG=DEBUG terraform plan

    Correct

    TF_LOG is an environment variable, so setting it only for one command enables logs for that run alone.

  • BRun terraform plan -log=debug

    Incorrect

    Terraform has no -log option; logging is controlled by TF_LOG.

  • CAdd log_level = "debug" to the terraform block

    Incorrect

    Logging is not configured in the terraform block.

  • DRun terraform init -debug before the plan

    Incorrect

    init has no debug option and does not change later logging.

Scope logging to the command that needs it.

Question 4 · choose 1

An engineer misspells the level and sets TF_LOG=DEBGU. What happens when Terraform runs?

  1. ALogging is still turned on
  2. BTerraform refuses to run any command until the value is corrected
  3. CLogging stays off
  4. DTerraform writes only errors
Show the answer and why
  • ALogging is still turned on

    Correct

    Detailed logs are enabled by setting TF_LOG to any value; the level names refine verbosity.

  • BTerraform refuses to run any command until the value is corrected

    Incorrect

    Terraform does not stop for an unknown level.

  • CLogging stays off

    Incorrect

    Any value enables logging.

  • DTerraform writes only errors

    Incorrect

    Detailed logging is enabled.

Use a level name to control verbosity; any value turns logging on.

Question 5 · choose 1

When is enabling TF_LOG most useful?

  1. AOn every production run, because logging makes plans and applies faster
  2. BTo encrypt the state file
  3. CTo format configuration files
  4. DWhen debugging unexpected behavior or unclear errors
Show the answer and why
  • AOn every production run, because logging makes plans and applies faster

    Incorrect

    Logging adds output; it does not speed anything up.

  • BTo encrypt the state file

    Incorrect

    Logging has nothing to do with encryption.

  • CTo format configuration files

    Incorrect

    That is terraform fmt.

  • DWhen debugging unexpected behavior or unclear errors

    Correct

    Terraform's detailed logs help debug unexpected behavior.

Turn logging on when you need to understand a problem, then off.

Question 6 · choose 1

An apply fails with an unclear error that looks like a bug. The engineer reruns it with TF_LOG set and keeps the log, then has to decide whether the issue belongs with the Terraform core team or with the provider's maintainers. What does HashiCorp's troubleshooting tutorial advise?

  1. ARerun with TF_LOG=JSON, since only JSON logs show which component wrote each line
  2. BRun terraform validate; if it passes, the error must come from the provider
  3. CTrace the final error in the log to its source; provider errors name the plugin
  4. DOpen every issue with the Terraform core team, which passes provider issues on
Show the answer and why
  • ARerun with TF_LOG=JSON, since only JSON logs show which component wrote each line

    Incorrect

    Plain-text logs already show the source: one log holds both the provider's lines, labeled with its plugin name, and Terraform core's lines.

  • BRun terraform validate; if it passes, the error must come from the provider

    Incorrect

    validate only rules out configuration errors; a valid configuration can still hit a core bug or a provider bug, and the log shows which.

  • CTrace the final error in the log to its source; provider errors name the plugin

    Correct

    The tutorial says to find the final error message in the log and trace it back to its source; a provider issue names the provider's plugin, such as terraform-provider-aws.

  • DOpen every issue with the Terraform core team, which passes provider issues on

    Incorrect

    Providers are maintained separately: the tutorial sends provider issues to the provider's own repository, found through the Registry, and core issues to the Terraform repository.

Language errors show up in fmt and validate; once they are ruled out, the log tells a core error from a provider error, and each goes to its own team.

Practise domain 7 →Practise all domains →