In this lecture,
we will learn how to enable and use debugging in Terraform.
When things go wrong in Terraform,
the obvious place to look for the cause is in the logs.
Although Terraform apply often provides
a good indication of what may have caused
an error during the provisioning,
there may be cases where we need
to look a little bit deeper.
To do this
we can make use of environment variable
called tf_log
and set it to one of the log level values.
Terraform offers file log levels,
info,
warning,
error,
debug and trace,
with trace being the most verbose logging level of them all.
When we run Terraform commands
after setting the environment variable,
we should see a lot of additional logs
based on the level that has been set.
For example,
a simple Terraform plan with logging set to trace
would display hundreds and thousands of lines,
including those
that are run internally by the Terraform plugin in use.
These logs are particularly useful
when things are not working as expected
within Terraform internally.
In such cases,
the logs generated can also be used
to file a bug report with Terraform.
To store the logs persistently in a file,
use the environment variable called tf_log_part
and point it to a file like this.
This will ensure that
all the logs that are generated are recorded in that file.
To disable logging completely,
unset the environment variables like this.
That's it for this lecture.
Let's head over to the hands-on lab
and practice working with Terraform taint and debugging.