Skip to main content
In this tutorial, you’ll learn how to update and destroy infrastructure managed by OpenTofu using a simple local_file example. We’ll walk through modifying resource configuration, previewing changes, applying updates, tearing down resources, and organizing your .tf files for maintainability.

🔄 Updating a Resource

To change an existing local_file resource, edit its configuration. In this example, we add the file_permission argument and set it to "0700":
Next, preview the plan with:
Output (truncated):
Save your plan with tofu plan -out=plan.tfplan to lock in the exact changes for later application.

Understanding the Plan Output

  • The -/+ indicator shows the resource will be destroyed and recreated.
  • # forces replacement highlights why OpenTofu must rebuild the resource—in this case, due to a permission change.
  • The summary line (e.g., 1 to add, 0 to change, 1 to destroy) gives a quick overview of the plan.

✅ Applying the Update

To apply the pending changes, run:
You’ll see the same plan, then a confirmation prompt:

🗑️ Destroying a Resource

When you no longer need the local_file resource, use:
Example output:
Adding -auto-approve skips all confirmation prompts. Use with caution, as it will immediately destroy your managed resources.

🗂️ Organizing Configuration Files

OpenTofu loads all .tf files in the working directory. Splitting configurations into multiple files can enhance readability and maintainability. For example, a directory with two resources:
local.tf
cat.tf
When you run tofu apply, both resources are created together.

Single vs. Multiple Files

Alternatively, you can combine all resources in one main.tf:
As your project grows, consider splitting into:
  • variables.tf
  • outputs.tf
  • providers.tf
  • main.tf
This structure improves clarity and makes collaboration easier.

Watch Video