WEBVTT

00:02.940 --> 00:04.110
In this lecture,

00:04.110 --> 00:04.650
we will learn

00:04.650 --> 00:06.650
how to update and destroy

00:06.650 --> 00:08.650
infrastructure using Terraform.

00:10.370 --> 00:11.420
In the previous lecture,

00:11.450 --> 00:13.650
we saw how to create a local file.

00:14.450 --> 00:14.850
Now

00:15.170 --> 00:16.850
let us see how we can update

00:17.050 --> 00:18.540
and destroy this resource

00:18.540 --> 00:20.540
using Terraform.

00:20.540 --> 00:21.220
First,

00:21.220 --> 00:23.220
let us try to update this resource.

00:24.220 --> 00:26.850
Let us add in a file permission argument

00:26.850 --> 00:28.850
to update the permission of the file

00:29.170 --> 00:30.850
to 0700

00:30.940 --> 00:34.170
instead of the default value of 0777.

00:34.940 --> 00:36.420
This will remove any permission

00:36.510 --> 00:39.680
for everyone else except the owner of the file.

00:40.050 --> 00:40.820
Now,

00:40.820 --> 00:42.480
if we're on Terraform plan,

00:42.480 --> 00:44.480
we will see an output like this.

00:45.910 --> 00:47.000
From the output,

00:47.000 --> 00:50.220
we can see that the resource will be replaced.

00:50.800 --> 00:52.220
The minus plus symbol

00:52.220 --> 00:53.940
in the beginning of the resource name

00:54.880 --> 00:54.910
in the plan

00:54.910 --> 00:56.680
implies that it will be deleted

00:56.680 --> 00:58.680
and then recreated.

00:58.880 --> 01:02.400
The line with the command that reads "forces replacement"

01:02.400 --> 01:05.420
is responsible for the deletion and recreation.

01:05.650 --> 01:07.000
In this example,

01:07.000 --> 01:09.650
this is caused by the file permission argument

01:09.650 --> 01:12.080
that we added to the configuration file.

01:13.400 --> 01:15.850
Even though the change we made was trivial,

01:16.110 --> 01:17.970
Terraform will delete the old file

01:17.970 --> 01:19.400
and then create a new file

01:19.400 --> 01:21.400
with the updated permissions.

01:21.800 --> 01:23.880
This type of infrastructure is called

01:23.880 --> 01:25.880
an immutable infrastructure.

01:26.110 --> 01:27.450
We saw this briefly

01:27.450 --> 01:30.370
when we discussed the different types of IAC tools.

01:31.570 --> 01:33.680
If you want to go ahead with the change,

01:33.850 --> 01:35.680
use the Terraform apply command

01:36.050 --> 01:39.000
and then type "yes" when prompted.

01:39.650 --> 01:41.140
Upon confirmation,

01:41.140 --> 01:42.680
the existing file is deleted

01:42.680 --> 01:45.280
and recreated with the new permissions.

01:46.340 --> 01:48.420
To delete the infrastructure completely,

01:48.570 --> 01:50.420
run the Terraform destroy command.

01:51.740 --> 01:54.420
This command shows the execution plan as well,

01:54.540 --> 01:56.110
and you can see the resource

01:56.110 --> 01:57.620
and all of its arguments

01:57.620 --> 01:59.620
have a minus symbol next to them.

02:00.370 --> 02:03.000
This indicates that the resource will be destroyed.

02:03.710 --> 02:05.540
To go ahead with the destroy

02:05.620 --> 02:07.540
confirm "yes" in the prompt.

02:08.340 --> 02:12.200
This will delete all the resources in the current configuration directory.

02:12.880 --> 02:13.970
In this example,

02:13.970 --> 02:17.910
it deletes the file/route/pets.ext.

02:19.200 --> 02:20.450
That's it for this lecture.

02:20.680 --> 02:22.850
Let's head over to the hands-on labs

02:22.850 --> 02:24.170
and practice updating

02:24.170 --> 02:27.280
and deleting infrastructure resources using Terraform.

