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 existinglocal_file resource, edit its configuration. In this example, we add the file_permission argument and set it to "0700":
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 replacementhighlights 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:🗑️ Destroying a Resource
When you no longer need thelocal_file resource, use:
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
tofu apply, both resources are created together.
Single vs. Multiple Files
Alternatively, you can combine all resources in onemain.tf:
variables.tfoutputs.tfproviders.tfmain.tf