WEBVTT

00:01.680 --> 00:02.650
In this lecture,

00:02.650 --> 00:04.650
we will take a look at the different types

00:04.650 --> 00:06.650
of resource dependencies in Terraform.

00:07.940 --> 00:09.020
in the previous lecture,

00:09.020 --> 00:11.020
we saw how to link one resource

00:11.020 --> 00:13.340
to another using reference attributes.

00:13.880 --> 00:16.770
By making use of reference expression and interpolation,

00:17.200 --> 00:18.880
we were able to make use of the

00:18.880 --> 00:20.880
output of the random_pet resource

00:20.880 --> 00:23.050
as an input for the local file resource.

00:23.880 --> 00:24.420
now

00:24.710 --> 00:26.570
when Terraform creates these resources,

00:26.570 --> 00:28.020
it knows about the dependency

00:28.140 --> 00:29.880
since the local file resource

00:29.880 --> 00:32.420
depends on the output of the random_pet resource.

00:33.280 --> 00:34.220
As a result,

00:34.220 --> 00:36.420
it uses the following order to provision them.

00:36.970 --> 00:37.620
first

00:37.620 --> 00:39.620
Terraform crazy random_pet resource,

00:39.620 --> 00:42.800
and then it creates a local file resource.

00:43.600 --> 00:45.140
When resources are deleted,

00:45.370 --> 00:47.370
and Terraform deletes it in the reverse order,

00:47.710 --> 00:50.420
the local file first and then the random bid.

00:51.110 --> 00:54.110
This type of dependency is called the implicit dependency.

00:54.620 --> 00:59.420
Here, we're not explicitly specifying which resource is dependent on which other resource.

01:00.050 --> 01:01.970
Terraform figures it out by itself.

01:02.820 --> 01:07.570
However, there's another way to specify dependency within the configuration file.

01:07.880 --> 01:08.820
For example,

01:09.280 --> 01:11.570
let us make use of the older configuration file

01:11.570 --> 01:15.540
without making use of the reference expression for the file content.

01:16.020 --> 01:18.620
If you still want to make sure that the local file resource

01:18.620 --> 01:20.620
is created after the random_pet,

01:20.970 --> 01:24.740
we can do this by using the depends on argument like this.

01:26.050 --> 01:26.710
here

01:26.710 --> 01:28.710
we have added a depends on argument inside

01:28.710 --> 01:30.710
the resource block for the local file,

01:31.200 --> 01:33.220
and we are provided a list of dependencies

01:33.220 --> 01:36.140
that include the random_pet resource called the my pet.

01:36.800 --> 01:38.480
This will ensure that the local file

01:38.480 --> 01:41.600
is only created after the random_pet resource is created.

01:42.510 --> 01:46.140
This type of dependency is called an explicit dependency.

01:47.050 --> 01:49.370
Explicitly specifying a dependency

01:49.370 --> 01:52.080
is only necessary when a resource relies on

01:52.080 --> 01:54.080
some other resource indirectly,

01:54.220 --> 01:57.510
and it does not make use of a reference expression as seen in this case.

01:58.370 --> 02:00.680
In the later sections of this course, we will see

02:00.770 --> 02:03.820
how and when to use this in a real-world use case.

02:04.710 --> 02:06.850
Now let's head over to the hands-on labs

02:06.850 --> 02:10.200
and explore working with resource dependencies in Terraform.

