- Terraform Debug is a feature that allows you to troubleshoot and diagnose issues with your Terraform configurations and state.
TF_LOG
- Specify the logging levelTF_LOG_PATH
- Specify the path for log file
-
TRACE : Provides the most detailed logging, including extensive information about internal operations and API requests/responses.
-
DEBUG : Provides debug-level logging, including detailed information about Terraform's actions and decisions.
-
INFO : Provides informational logging, showing high-level information about what Terraform is doing.
-
WARN : Provides warning messages, indicating potential issues or non-fatal errors.
-
ERROR : Provides error messages only, indicating critical issues that prevent Terraform from completing an operation.
-
Run the following commands
export TF_LOG=TRACE export TF_LOG_PATH="terraform-trace.log" echo $TF_LOG echo $TF_LOG_PATH
-
You can than execute terraform commands to get the
TRACE
logs stored interraform-trace.log
file# Terraform Initialize terraform init # Terraform Validate terraform validate # Terraform Plan terraform plan # Terraform Apply terraform apply -auto-approve # Terraform Destroy terraform destroy -auto-approve # Clean-Up rm -rf .terraform* rm -rf terraform.tfstate* rm terraform-trace.log
-
Open your
.bashrc
which is located in your $home directory# Linux Bash cd $HOME vi .bashrc # Terraform log settings export TF_LOG=TRACE export TF_LOG_PATH="terraform-trace.log" # Verify after saving the file in new terminal $ echo $TF_LOG TRACE $ echo $TF_LOG_PATH terraform-trace.log
- Setup using Powershell profile
- Open
$profile
command in a PowerShell - Once that file is opened add the following lines.
- Now close and reopen the console and type the following to verify that it worked.
# Windows Powershell - Terraform log settings $env:TF_LOG="TRACE" $env:TF_LOG_PATH="terraform.txt" # Open new powershell window & Verify echo $env:TF_LOG echo $env:TF_LOG_PATH
- Update the values in
.bash_profile
at the end of file# MAC OS cd $HOME vi .bash_profile # Terraform log settings export TF_LOG=TRACE export TF_LOG_PATH="terraform-trace.log" # Verify after saving the file in new terminal $ echo $TF_LOG TRACE $ echo $TF_LOG_PATH terraform-trace.log
- If Terraform ever crashes (a "panic" in the Go runtime), it saves a log file with the debug logs from the session as well as the panic message and backtrace to
crash.log
. - Generally speaking, this log file is meant to be passed along to the developers via a GitHub Issue.
- How to read a crash log?
References:
https://developer.hashicorp.com/terraform/internals/debugging