WEBVTT

00:00.510 --> 00:01.740
In this lecture,

00:01.740 --> 00:05.370
we will learn how to enable and use debugging in Terraform.

00:06.880 --> 00:08.800
When things go wrong in Terraform,

00:08.940 --> 00:12.540
the obvious place to look for the cause is in the logs.

00:12.740 --> 00:15.050
Although Terraform apply often provides

00:15.050 --> 00:17.110
a good indication of what may have caused

00:17.110 --> 00:18.600
an error during the provisioning,

00:18.880 --> 00:20.710
there may be cases where we need

00:20.710 --> 00:22.250
to look a little bit deeper.

00:22.820 --> 00:23.820
To do this

00:23.820 --> 00:25.820
we can make use of environment variable

00:25.820 --> 00:27.710
called tf_log

00:27.820 --> 00:30.510
and set it to one of the log level values.

00:31.510 --> 00:33.710
Terraform offers file log levels,

00:33.910 --> 00:34.740
info,

00:34.740 --> 00:35.770
warning,

00:35.770 --> 00:36.540
error,

00:36.540 --> 00:38.000
debug and trace,

00:38.000 --> 00:41.370
with trace being the most verbose logging level of them all.

00:42.220 --> 00:44.080
When we run Terraform commands

00:44.080 --> 00:46.280
after setting the environment variable,

00:46.280 --> 00:48.740
we should see a lot of additional logs

00:48.740 --> 00:50.740
based on the level that has been set.

00:51.370 --> 00:52.420
For example,

00:52.420 --> 00:55.600
a simple Terraform plan with logging set to trace

00:55.600 --> 00:58.280
would display hundreds and thousands of lines,

00:58.280 --> 00:59.140
including those

00:59.140 --> 01:01.910
that are run internally by the Terraform plugin in use.

01:02.540 --> 01:04.940
These logs are particularly useful

01:04.940 --> 01:06.940
when things are not working as expected

01:06.940 --> 01:08.450
within Terraform internally.

01:08.850 --> 01:10.020
In such cases,

01:10.020 --> 01:12.020
the logs generated can also be used

01:12.020 --> 01:14.020
to file a bug report with Terraform.

01:15.050 --> 01:17.510
To store the logs persistently in a file,

01:17.510 --> 01:21.480
use the environment variable called tf_log_part

01:21.480 --> 01:23.740
and point it to a file like this.

01:24.480 --> 01:25.400
This will ensure that

01:25.400 --> 01:28.510
all the logs that are generated are recorded in that file.

01:29.740 --> 01:31.620
To disable logging completely,

01:31.620 --> 01:34.020
unset the environment variables like this.

01:35.220 --> 01:36.510
That's it for this lecture.

01:36.740 --> 01:38.510
Let's head over to the hands-on lab

01:38.510 --> 01:41.340
and practice working with Terraform taint and debugging.

