Updating a Resource
To update a resource in Terraform, simply modify the configuration file. For example, you might add a new argument to update the file permissions of a resource to “0700”:Running
terraform plan is optional because executing terraform apply displays the same execution plan.Destroying a Resource
To remove a resource completely from your infrastructure, use theterraform destroy command. This command generates an execution plan that shows a minus symbol next to each resource set for removal. Review the plan carefully before confirming the destruction.
auto-approve flag with the terraform destroy command. Use this option with caution, as it immediately removes all managed resources.
Organizing Your Configuration Directory
Terraform treats any file with a.tf extension found in the current working directory as part of your configuration. This allows you to split your infrastructure configuration across multiple files for better organization. For instance, if your configuration is stored under /root/terraform-local-file with an initial file named local.tf, your directory might look like this:
local.tf file may contain a resource like:
cat.tf, to define an additional resource:
terraform apply for the first time.
A common best practice is to consolidate resource blocks into a single configuration file (often named main.tf) while separating variables and outputs into dedicated files such as variables.tf and outputs.tf. This modular structure improves manageability, especially as your project grows in complexity.
That concludes our guide on updating and destroying Terraform-managed infrastructure resources. To reinforce your understanding, consider taking the multiple-choice quiz and testing your knowledge of these Terraform operations.