Skip to main content
This guide will walk you through updating and destroying infrastructure using Terraform. In previous tutorials, we covered how to create a local file resource. Today, we will update its configuration and then completely destroy it.

Updating the Resource

In this section, we update the local file resource by changing its file permissions from the default (0777) to a more secure permission (0700). This update restricts file access exclusively to the owner. Below is the updated Terraform configuration:
Updating this configuration marks the current resource as needing replacement. When you run the Terraform plan, you will see that Terraform plans to replace the resource. The output indicates the replacement using the symbol ”-/+” to show that Terraform will destroy the existing file and create a new one with the updated permissions. Below is an example of the Terraform plan output:
Even though the configuration change is minor, Terraform treats the resource as immutable. This means the old resource is destroyed and a new one is created with the updated settings.
To proceed with applying these changes, run the Terraform apply command. Confirm the action by typing “yes” when prompted:

Destroying the Resource

When you need to completely delete the infrastructure, use the Terraform destroy command. Running this command will generate an execution plan that shows every attribute of the resource marked for deletion. The minus symbol (-) indicates that each attribute will be removed. Below is an example output from the Terraform destroy command:
Double-check your plan before running the destroy command, as this action will permanently delete all managed resources in the current configuration.

Conclusion

You have now learned how to update and destroy infrastructure using Terraform. Updating a resource triggers a replacement, while the destroy command allows for the complete removal of the resource. Practice these steps to reinforce your Terraform skills and better manage your infrastructure lifecycle.

Watch Video

Practice Lab