nerdexam
HashiCorp

TA-002-P · Question #198

You have already set TF_LOG = DEBUG to enable debug log. Now you want to always write the log to the directory you're currently running terraform from. what should you do to achieve this.

The correct answer is B. Run the command export TF_LOG_PATH=./terraform.log. TF_LOG_PATH is the correct environment variable to specify the file path where Terraform debug logs are written.

Use the Terraform CLI (terraform plan, apply, destroy, fmt, init, validate, workspace, import, taint, providers, output)

Question

You have already set TF_LOG = DEBUG to enable debug log. Now you want to always write the log to the directory you're currently running terraform from. what should you do to achieve this.

Options

  • ARun the command export TF_LOG_FILE=./terraform.log.
  • BRun the command export TF_LOG_PATH=./terraform.log.
  • CRun the command export TF_DEBUG_PATH=./terraform.log.
  • DNo explicit action required. Terraform will take care of this as you have enable TF_LOG.

How the community answered

(25 responses)
  • A
    4% (1)
  • B
    88% (22)
  • D
    8% (2)

Why each option

`TF_LOG_PATH` is the correct environment variable to specify the file path where Terraform debug logs are written.

ARun the command export TF_LOG_FILE=./terraform.log.

`TF_LOG_FILE` is not a recognized Terraform environment variable; using it will have no effect on log output.

BRun the command export TF_LOG_PATH=./terraform.log.Correct

Terraform uses `TF_LOG_PATH` to redirect log output from stderr to a specified file path. Setting `TF_LOG_PATH=./terraform.log` writes logs to `terraform.log` in the current working directory. Without this variable, logs only appear on stderr even when `TF_LOG` is set.

CRun the command export TF_DEBUG_PATH=./terraform.log.

`TF_DEBUG_PATH` is not a valid Terraform environment variable and will not redirect any log output.

DNo explicit action required. Terraform will take care of this as you have enable TF_LOG.

Setting `TF_LOG` alone only enables logging to stderr; a separate `TF_LOG_PATH` variable is required to persist logs to a file.

Concept tested: Terraform debug logging with TF_LOG_PATH

Source: https://developer.hashicorp.com/terraform/internals/debugging

Topics

#Terraform logging#Debug logging#Environment variables#Terraform CLI

Community Discussion

No community discussion yet for this question.

Full TA-002-P Practice