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.
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.)
ATF_LOG must also be set, because TF_LOG_PATH alone does not enable logging
BTF_LOG_PATH works only with the JSON log format
CWith TF_LOG set, the log is appended to that file
DTF_LOG_PATH must point to an existing directory, not to a file name
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.
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?
APrefix it: TF_LOG=DEBUG terraform plan
BRun terraform plan -log=debug
CAdd log_level = "debug" to the terraform block
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.
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?
ARerun with TF_LOG=JSON, since only JSON logs show which component wrote each line
BRun terraform validate; if it passes, the error must come from the provider
CTrace the final error in the log to its source; provider errors name the plugin
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.