WEBVTT

00:01.410 --> 00:03.290
-In this lecture,

00:03.290 --> 00:08.170
we will see how to use multiple providers
and resources in Terraform.

00:09.650 --> 00:14.840
Until now we have been making use
of a single provider called "local"

00:14.840 --> 00:17.450
to deploy a local file and the system.

00:18.160 --> 00:21.920
Terraform also supports the use
of multiple providers

00:21.920 --> 00:23.620
within the same configuration.

00:24.280 --> 00:25.930
To illustrate this,

00:25.930 --> 00:29.210
let's make use of another provider called
"random".

00:29.950 --> 00:35.910
This provider allows us to create
random resources such as a random ID

00:35.910 --> 00:39.790
or random integer or random password,
et cetera.

00:40.510 --> 00:45.930
Let us see how to use this provider
and create a resource called random_pet.

00:46.500 --> 00:51.280
This resource type will generate
a random pet name when applied.

00:52.270 --> 00:54.810
By making use of the documentation,

00:54.810 --> 00:59.830
we can add a resource block
to the existing main .tf file like this.

01:00.780 --> 01:01.830
Here,

01:01.830 --> 01:05.350
we are making use of the resource type
called random_pet.

01:06.080 --> 01:07.780
In an earlier lecture,

01:07.780 --> 01:11.270
we saw that the resource type
can be broken down to two parts.

01:11.270 --> 01:14.700
The keyword before the underscore
is the provider

01:14.700 --> 01:16.700
which in this case is random.

01:16.700 --> 01:21.190
The keyword following it
is the resource type which is the pet.

01:21.400 --> 01:24.140
Let's call this resource "my pet".

01:24.140 --> 01:27.770
Within this resource block,
we will use three arguments.

01:28.230 --> 01:32.110
One is the prefix
that is to be added to the pet name.

01:32.410 --> 01:36.540
The second argument is the separator
between the prefix

01:36.540 --> 01:38.390
and the pet name that is generated.

01:38.950 --> 01:43.630
The final argument is the length
which is the length of the pet name

01:43.630 --> 01:45.290
to be generated in words.

01:47.010 --> 01:52.290
A main .tf file now has resource definition
for two different providers,

01:52.880 --> 01:57.670
one resource of the local file type
that we have already created earlier

01:57.670 --> 02:01.040
and another resource of type random_pet.

02:01.540 --> 02:06.010
Before we generate an execution plan
and create these resources,

02:06.010 --> 02:08.850
we have to run
the Terraform init command again.

02:09.190 --> 02:11.400
Now, this is a mandatory step,

02:11.400 --> 02:14.870
as the plugin for the random provider
should be initializing

02:14.870 --> 02:18.100
the configuration directory
before we can make use of it.

02:19.130 --> 02:22.020
In the command output of the Terraform init,

02:22.020 --> 02:25.630
we can see that the local provider
was previously installed

02:25.630 --> 02:27.190
and it will be reused.

02:27.450 --> 02:30.380
The plug-in for the random provider,
on the other hand,

02:30.380 --> 02:33.470
will be installed as it was not used before.

02:34.100 --> 02:38.690
We can now run the Terraform plan
to review the execution plan.

02:39.320 --> 02:43.270
As expected,
the local file resource called "pet"

02:43.270 --> 02:47.640
will not be updated as it is unchanged
from the previous apply.

02:48.110 --> 02:52.930
A new resource by the name of "my pet"
will be created based

02:52.930 --> 02:55.400
on the new resource block that we just added.

02:56.310 --> 02:59.800
Now let's apply the configuration
using Terraform apply.

03:00.630 --> 03:05.800
As expected, the local file resource
is left as it is but now

03:05.800 --> 03:09.510
a new resource has been created
which is called "my pet".

03:10.820 --> 03:15.120
Random provider is a logical provider
and it displays the results

03:15.120 --> 03:17.650
of the pet name on the screen like this.

03:18.810 --> 03:23.250
Here, an attribute called ID
which contains the name of the pet

03:23.250 --> 03:25.250
is written by the apply command.

03:26.050 --> 03:30.420
Before we move on,
please know that in our illustration,

03:30.420 --> 03:34.860
the dog icon stands for a pet
and we'll be making use of it

03:34.860 --> 03:36.110
throughout this course.

03:36.440 --> 03:42.160
The random_pet can generate any pet name
and it does not have to be specifically a dog.

03:42.790 --> 03:47.200
Now, let's head over to the hands-on labs
and explore working

03:47.200 --> 03:49.770
with multiple providers in Terraform.

