In this lecture,
we will take a look at the different types
of resource dependencies in Terraform.
in the previous lecture,
we saw how to link one resource
to another using reference attributes.
By making use of reference expression and interpolation,
we were able to make use of the
output of the random_pet resource
as an input for the local file resource.
now
when Terraform creates these resources,
it knows about the dependency
since the local file resource
depends on the output of the random_pet resource.
As a result,
it uses the following order to provision them.
first
Terraform crazy random_pet resource,
and then it creates a local file resource.
When resources are deleted,
and Terraform deletes it in the reverse order,
the local file first and then the random bid.
This type of dependency is called the implicit dependency.
Here, we're not explicitly specifying which resource is dependent on which other resource.
Terraform figures it out by itself.
However, there's another way to specify dependency within the configuration file.
For example,
let us make use of the older configuration file
without making use of the reference expression for the file content.
If you still want to make sure that the local file resource
is created after the random_pet,
we can do this by using the depends on argument like this.
here
we have added a depends on argument inside
the resource block for the local file,
and we are provided a list of dependencies
that include the random_pet resource called the my pet.
This will ensure that the local file
is only created after the random_pet resource is created.
This type of dependency is called an explicit dependency.
Explicitly specifying a dependency
is only necessary when a resource relies on
some other resource indirectly,
and it does not make use of a reference expression as seen in this case.
In the later sections of this course, we will see
how and when to use this in a real-world use case.
Now let's head over to the hands-on labs
and explore working with resource dependencies in Terraform.