In this lecture,
we will learn
how to update and destroy
infrastructure using Terraform.
In the previous lecture,
we saw how to create a local file.
Now
let us see how we can update
and destroy this resource
using Terraform.
First,
let us try to update this resource.
Let us add in a file permission argument
to update the permission of the file
to 0700
instead of the default value of 0777.
This will remove any permission
for everyone else except the owner of the file.
Now,
if we're on Terraform plan,
we will see an output like this.
From the output,
we can see that the resource will be replaced.
The minus plus symbol
in the beginning of the resource name
in the plan
implies that it will be deleted
and then recreated.
The line with the command that reads "forces replacement"
is responsible for the deletion and recreation.
In this example,
this is caused by the file permission argument
that we added to the configuration file.
Even though the change we made was trivial,
Terraform will delete the old file
and then create a new file
with the updated permissions.
This type of infrastructure is called
an immutable infrastructure.
We saw this briefly
when we discussed the different types of IAC tools.
If you want to go ahead with the change,
use the Terraform apply command
and then type "yes" when prompted.
Upon confirmation,
the existing file is deleted
and recreated with the new permissions.
To delete the infrastructure completely,
run the Terraform destroy command.
This command shows the execution plan as well,
and you can see the resource
and all of its arguments
have a minus symbol next to them.
This indicates that the resource will be destroyed.
To go ahead with the destroy
confirm "yes" in the prompt.
This will delete all the resources in the current configuration directory.
In this example,
it deletes the file/route/pets.ext.
That's it for this lecture.
Let's head over to the hands-on labs
and practice updating
and deleting infrastructure resources using Terraform.