Start with a Local File Instead of a Cloud Bill
The shortest mental model is “describe, preview, approve, check.” Terraform reads configuration (what you want), compares it with its state and the real file, then prints a plan (what it proposes). Apply carries out the reviewed proposal. Finally, inspect the file yourself. This article uses a local file so the complete lifecycle is practical without an AWS account, cloud credentials, or a bill.
Imagine ordering a printed sign from a shop. You write the wording on an order form. The shop checks what it made for you last time, quotes exactly what it will print and discard, and waits. You approve the quote; the shop prints. When the sign arrives, you do not take the shop's word that it is correct — you read it. Later, changing one word may mean a reprint from scratch rather than a dab of paint, because that is how the shop's process works. Cancelling the order recycles the sign, but the paperwork still exists.
Terraform's workflow has the same shape, and a local file lets you practise all of it without an account, a region, a credential or a bill. A few terms make the rest of this article readable.
- A provider is a plugin that knows how to act on one kind of system. Terraform Core compares desired and actual state; the provider performs the file write, API call or deletion.
- A resource is one object Terraform manages. Here it is
local_file.hello: the type islocal_file, the local name ishello. - State is Terraform's record of which addresses map to which objects, plus the attributes it last observed. It is not a backup of the object.
- A plan is a proposal: the actions Terraform would take under the current configuration, state and refreshed reality.
- Apply executes a plan. Destroy is the same machinery with the goal set to remove everything in state.
- Init prepares a working directory by installing and recording the providers the configuration requires.
The lab pins two versions and treats them as part of the exercise: Terraform CLI 1.17.1 and provider hashicorp/local 2.9.1, verified on 5 November 2026. The provider is published by HashiCorp and talks to your filesystem, so nothing crosses a network boundary after the initial download. No cloud account, payment method or credential is involved.
The configuration uses two resources. The first is the file. The second is Terraform's built-in terraform_data, which stores a value in state and creates nothing in the outside world. It is present for one reason: the local_file arguments used here all force replacement when changed, while terraform_data.input can be updated in place. That gives section five a real update marker to show. You can delete that block if you only want the file; the file lifecycle is unchanged.
flowchart TD
A["Write versions.tf and main.tf"] --> B["terraform init installs hashicorp/local 2.9.1"]
B --> C["terraform plan reads configuration, state and the current file"]
C --> D{"Object recorded in state?"}
D -->|"no"| E["Propose + create"]
D -->|"yes"| F{"Arguments differ from configuration?"}
F -->|"no"| G["Propose no changes"]
F -->|"yes"| H{"Changed argument forces replacement?"}
H -->|"yes"| I["Propose -/+ replacement"]
H -->|"no"| J["Propose ~ update in place"]
E --> K["Approve the saved plan"]
I --> K
J --> K
K --> L["Provider acts on the object"]
L --> M["State records the new result"]
G --> N["Nothing to apply"]
M --> O["Inspect the object independently"]
Figure 1 shows the whole loop before any command is run. The important boundary is not drawn between "local" and "cloud" for its own sake; it is drawn around the provider. Core never writes hello.txt. The plugin does, and only after a plan has been approved.
Figure 2 layers the four pieces and marks the single-machine boundary. Configuration is input, Core is the decision-maker, the provider is the hands, and the filesystem holds both the object and the record of it.
The configuration belongs in one root module: a directory whose .tf files Terraform reads as a unit. Filenames do not control execution order.
${path.module} resolves to "." in the root module, so the plan renders the path as ./hello.txt even though the file lands beside main.tf. file_permission is explicit because the provider's documented default is "0777" before the process umask, which usually becomes 0755; 0644 states the intent instead of inheriting it. The resource also records an id, which for this provider is the SHA-1 of the file content, and several checksum attributes that only exist after the file is written.
Initialize Providers and Inspect the Working Directory
terraform init is safe to run repeatedly, but the first run does the visible work: it reads the version constraints, selects a provider release, downloads the package for your OS and architecture, verifies it against registry checksums, installs it under .terraform, and writes .terraform.lock.hcl. The real output from the pinned run was:
Initializing the backend...
Initializing provider plugins...
- Finding hashicorp/local versions matching "2.9.1"...
- Installing hashicorp/local v2.9.1...
- Installed hashicorp/local v2.9.1 (signed by HashiCorp)
Terraform has created a lock file .terraform.lock.hcl to record the provider
selections it made above. Include this file in your version control repository
so that Terraform can guarantee to make the same selections by default when
you run "terraform init" in the future.
Two directories now matter, and they have opposite version-control rules.
.terraform/ is a machine-local cache. After our init it contained exactly one provider package:
.terraform/providers/registry.terraform.io/hashicorp/local/2.9.1/darwin_arm64/
terraform-provider-local_v2.9.1_x5
LICENSE.txt
Those are compiled binaries for one platform. They are large, reproducible from the lock file, and useless on a different OS or CPU. Some backend configurations also keep local metadata here. Delete the directory and init rebuilds it; commit it and you have added binaries and possibly machine-specific data to history. It belongs in .gitignore.
.terraform.lock.hcl is the decision record. Our file contained the selected version, the constraint that produced it, and fourteen checksums — one h1: content hash plus zh: zip hashes covering the platforms whose packages carry the registry's signed checksum set:
provider "registry.terraform.io/hashicorp/local" {
version = "2.9.1"
constraints = "2.9.1"
hashes = [
"h1:OZGJN0LSSat5QIxZPxDXtVr4XpHb2oG7cVKJhSqBFIE=",
"zh:25606c7a5e308144fb627f6e31611bb52ff72bb9ae2d27af39673ab1a6b3c1bf",
# ... twelve more zh: hashes for other platforms
]
}
Commit that file. The dependency-lock documentation is precise about the behaviour: if a provider already has a selection, init re-selects that version even when a newer one is available; -upgrade is the deliberate override. The checksums give a trust-on-first-use guarantee: if a later download does not match, installation fails rather than silently changing the plugin. It also means a teammate on Linux does not quietly get a different build from the one you tested.
A .gitignore that matches this lab and the next one:
.terraform/
*.tfstate
*.tfstate.*
*.tfplan
crash.log
The lock file is deliberately absent from that list. State and plan files are present because both can contain values copied from the resource — in this lab, the file's content appears in state. Terraform's own state documentation treats state as sensitive; this series returns to that in the state-inspection article.
Figure 3 follows init's decisions, including the branches that stop it. The happy path is short; most real failures are a constraint that cannot be satisfied, a package that fails checksum verification, or a registry that cannot be reached.
flowchart TD
A["terraform init"] --> B["Read required_version and required_providers"]
B --> C{"CLI satisfies required_version?"}
C -->|"no"| C1["Error: unsupported Terraform CLI version"]
C -->|"yes"| D{"Lock file selects hashicorp/local?"}
D -->|"yes"| E["Re-select the recorded 2.9.1"]
D -->|"no"| F["Query registry for newest release matching 2.9.1"]
F --> F1{"Release exists?"}
F1 -->|"no"| F2["Error: no available releases match the given constraints"]
F1 -->|"yes"| E
E --> G["Download the package for this OS and architecture"]
G --> H{"Checksum matches the lock file or signed set?"}
H -->|"no"| H1["Error: package does not match recorded checksums"]
H -->|"yes"| I["Install under .terraform/providers/"]
I --> J["Write or update .terraform.lock.hcl"]
J --> K["Ready for terraform plan"]
G -.->|"registry unreachable or mirror missing package"| G1["Error: failed to query available provider packages"]
The release-selection failure is easy to reproduce: change the constraint to a version that does not exist and init stops with Could not retrieve the list of available versions for provider hashicorp/local: no available releases match the given constraints. The checksum failure looks different — it names the provider and version and says the current package matches none of the hashes in the dependency lock file. Neither is a Terraform bug; both mean the inputs to selection changed. In CI, terraform init -lockfile=readonly verifies checksums without permitting a lock-file rewrite, which turns an accidental upgrade into a failed job rather than a surprise commit.
Read the Add, Change, Replace and Destroy Markers
A plan is built from three inputs: the configuration you wrote, the prior state, and a refreshed view of the real object. Terraform refreshes first because state can be stale — someone may have deleted or edited hello.txt since the last apply. It then compares and proposes actions. Figure 4 separates those inputs from the two outputs: a terminal summary and, if you asked for one, a saved plan file.
The plan legend is small enough to memorise, and each symbol answers a different question:
+create — the object is absent from state or was deleted outside Terraform.~update in place — the provider can change this attribute on the existing object.-destroy — the object exists in state but not in configuration, or a destroy plan was requested.-/+destroy and then create replacement — an argument that forces replacement changed. The old object goes first by default.
Our first plan, with two objects to create, printed + create once at the top and then a block per resource. The local_file block is the instructive one:
# local_file.hello will be created
+ resource "local_file" "hello" {
+ content = "Hello from Terraform."
+ content_base64sha256 = (known after apply)
+ content_base64sha512 = (known after apply)
+ content_md5 = (known after apply)
+ content_sha1 = (known after apply)
+ content_sha256 = (known after apply)
+ content_sha512 = (known after apply)
+ directory_permission = "0777"
+ file_permission = "0644"
+ filename = "./hello.txt"
+ id = (known after apply)
}
Plan: 2 to add, 0 to change, 0 to destroy.
content is known because you wrote it. id and the checksums are known after apply: they are computed by the provider from bytes that do not exist yet. The same applies to file_id, the output that references id. This is not a gap in the plan; it is the honest boundary between deciding and doing. A plan that pretended to know the hash of a file it had not written would be lying.
terraform plan -out=tfplan changes the artifact, not the decision. The terminal summary is speculative; the saved file is a plan Terraform can execute later without re-planning. terraform show tfplan renders it again for review. The plan documentation warns that the file contains the full configuration, every planned value and all input variables, and that sensitive data — even when redacted on screen — is saved in cleartext. Treat tfplan like a secret: keep it out of Git, out of tickets and out of chat, and delete it when the change is done. It is also tied to the state it was built from; applying it after another operation changes that state fails with Saved plan is stale, which is a safety feature rather than an inconvenience.
When there is nothing to do, the output is equally specific:
No changes. Your infrastructure matches the configuration.
Terraform has compared your real infrastructure against your configuration
and found no differences, so no changes are needed.
With -detailed-exitcode, that result exits 0. A successful plan with changes exits 2, and an error exits 1. Those three values are what let a pipeline distinguish "nothing to do" from "review this diff" from "the plan itself failed" without parsing prose.
Apply the Reviewed Plan and Verify the Result
Passing the saved plan to apply is the approval. terraform apply tfplan does not prompt, because the act of naming the file is treated as consent to exactly those actions; the apply documentation notes that this includes destructive actions. If you run plain terraform apply, Terraform builds a fresh plan and asks you to approve it, which is fine interactively but weaker for review, since the thing you approved and the thing that runs are separated by a prompt.
The pinned run produced:
terraform_data.revision: Creating...
terraform_data.revision: Creation complete after 0s [id=cc03ebc6-...]
local_file.hello: Creating...
local_file.hello: Creation complete after 0s [id=5b011e8245a8582ccff8584a5e31382f79930490]
Apply complete! Resources: 2 added, 0 changed, 0 destroyed.
Outputs:
file_id = "5b011e8245a8582ccff8584a5e31382f79930490"
The two creates are independent, so their order in the log is not guaranteed; the summary counts are the stable part.
That summary is a statement about provider operations, not about your requirements. It says two objects were created; it does not say the file is at the right path, has the right bytes, or carries the permission you intended. Verification is a separate act with separate tools:
$ cat hello.txt
Hello from Terraform.
$ ls -l hello.txt
-rw-r--r-- 1 user staff 21 Nov 5 14:30 hello.txt
$ shasum -a 256 hello.txt
6b718e17720128dc1f9207ed147a3d781fd84ded72f3c01576c3ba77cb490b3c
$ terraform state list
local_file.hello
terraform_data.revision
$ terraform output
file_id = "5b011e8245a8582ccff8584a5e31382f79930490"
Four independent facts line up. The content is the string from the configuration. The mode is 0644, not the provider's 0777 default filtered by umask. The SHA-256 reported by the operating system matches content_sha256 in terraform state show local_file.hello, while id is the SHA-1 of the same bytes. terraform state list confirms two addresses, not one file and one mystery object.
This is also where a subtle failure hides. The local provider's documentation warns that a file missing on a new machine is treated as deleted, so the next plan proposes to create it again. We tested that: after rm hello.txt, terraform plan showed + create for local_file.hello even though state still contained the old address and checksums. Nothing was corrupted; refresh updated the record to match reality. The lesson is that "apply succeeded yesterday" is not evidence that the object exists today. The check that matters is the one you run now.
If apply fails partway, Terraform does not roll back. It writes the changes it managed, unlocks state and exits. With one local file the blast radius is a missing or partially written file, but the habit is the same one that matters for a database or a load balancer: inspect before re-running, because a second apply plans from the new reality rather than from the plan you approved.
Change One Argument and Predict the Next Plan
Change content from "Hello from Terraform." to "Hello from Terraform, second draft." and predict before running anything. The edit is one line, so an in-place update feels natural. The provider schema says otherwise:
# local_file.hello must be replaced
-/+ resource "local_file" "hello" {
~ content = "Hello from Terraform." -> "Hello from Terraform, second draft." # forces replacement
~ content_sha1 = "5b011e8245a8582ccff8584a5e31382f79930490" -> (known after apply)
~ id = "5b011e8245a8582ccff8584a5e31382f79930490" -> (known after apply)
# ... other checksum attributes recomputed
# (3 unchanged attributes hidden)
}
Plan: 1 to add, 0 to change, 1 to destroy.
# forces replacement is the line to read. In hashicorp/local 2.9.1, the filename, content and permission arguments used here are all replacement-triggering; the provider has no in-place path for them. Applying the saved plan therefore destroys the old object and creates a new one. The file ends up with the new text, but its id changes because the id is derived from the content. The summary reads 1 added, 0 changed, 1 destroyed, and the output's file_id changes with it.
Terraform is not deciding that a one-line edit deserves a heavy hammer. The provider is reporting what its update implementation supports. That distinction generalises: a tag change on a cloud resource may update in place, while an availability-zone change may force replacement, and the plan tells you which before you commit.
To see the other marker in the same lab, change the control object instead:
# terraform_data.revision will be updated in-place
~ resource "terraform_data" "revision" {
id = "cc03ebc6-0369-8264-fc0c-b3d798de65e5"
~ input = "draft-1" -> "draft-2"
~ output = "draft-1" -> (known after apply)
}
Plan: 0 to add, 1 to change, 0 to destroy.
This is a true in-place update. The address and id survive; only the stored value and the derived output change, and the output is unknown until apply because the provider has not recomputed it. Applying it reports 0 added, 1 changed, 0 destroyed. Figure 5 puts the two edits side by side: two one-line edits, two different lifecycle outcomes, both decided by the provider rather than by Terraform Core.
The empty plan after apply is the proof that the marker predicted the outcome. If the update plan had been wrong, the next plan would still show a diff. Run terraform plan -detailed-exitcode and expect 0.
There is also a deliberate way to replace an object whose arguments did not change: terraform plan -replace=local_file.hello asks for replacement explicitly. That is the documented tool for a degraded object, and it is preferable to editing an unrelated argument just to force a new file. Use it when you want replacement, not as a routine step.
Destroy the Resource and Explain the Remaining Files
Destroy is not a separate mechanism. terraform destroy is a convenience alias for terraform apply -destroy; it forces destroy planning mode, prompts for approval and does not accept a saved plan file. For review, build the destroy plan first and apply that file:
$ terraform plan -destroy -out=destroy.tfplan
...
# local_file.hello will be destroyed
- resource "local_file" "hello" { ... }
# terraform_data.revision will be destroyed
- resource "terraform_data" "revision" { ... }
Plan: 0 to add, 0 to change, 2 to destroy.
$ terraform apply destroy.tfplan
terraform_data.revision: Destroying... [id=cc03ebc6-...]
terraform_data.revision: Destruction complete after 0s
local_file.hello: Destroying... [id=1d1979248d30433b8c337ae3674e747bdcb6e44f]
local_file.hello: Destruction complete after 0s
Apply complete! Resources: 0 added, 0 changed, 2 destroyed.
hello.txt is gone. So is every resource address: terraform state list prints nothing. But the working directory is not empty, and "destroyed" does not mean "deleted".
versions.tf,main.tfand your output block remain. They are the desired state; destroying objects does not rewrite the code that describes them. Runningterraform applyagain would recreate both objects, including the file..terraform/remains: the cached provider binary, ready for the next operation..terraform.lock.hclremains and still records 2.9.1. Commit it; the lifecycle did not change the dependency decision.terraform.tfstateremains, now with"resources": [], an incremented serial and the same lineage. Terraform keeps the file to record that the state exists and that nothing is managed. Deleting it would not destroy anything; it would only make Terraform forget the addresses.terraform.tfstate.backupremains and holds the previous snapshot. In our run it still contained the old file content after destroy. That backup is a confidentiality issue if the object held secrets, which is one reason state files do not belong in Git.tfplan,replace.tfplan,update.tfplananddestroy.tfplanremain. They are sensitive artifacts and should be deleted when no longer needed.hello.txtdoes not remain. That is the only external artifact destroy was asked to remove.
The distinctions are worth stating plainly because they are conflated constantly. Destroying infrastructure is a provider action driven by state. Deleting code changes the desired state but performs nothing until the next apply. Deleting state forgets the mapping and leaves the real object in place. Deleting a plan file deletes only a proposal. None of these is a substitute for another.
Complete the local lifecycle
Execution status: executed on 5 November 2026 on macOS (darwin_arm64) with Terraform 1.17.1 and hashicorp/local 2.9.1. The results quoted here are from that run; identifiers and machine paths are sanitized, and no cloud account, credential or payment method was used.
Prerequisites. Terraform 1.17.1 available as terraform (terraform version must report it), network access to registry.terraform.io for the first init, and a scratch directory. Budget roughly 150 MB if you also download the CLI; the provider package alone is about 17 MB. No cloud account or credentials.
Minimal setup. Create tf-local-lab/ and add versions.tf and main.tf exactly as shown in the first section, including the local_file.hello resource, the terraform_data.revision control object and the file_id output. This is the same configuration the article executed.
- Run
terraform init. ExpectInstalled hashicorp/local v2.9.1 (signed by HashiCorp)and the message that.terraform.lock.hclwas created. Runfind .terraform -type f; expect the platform-specific provider binary and its licence, nothing else. - Run
terraform plan -out=tfplan. ExpectPlan: 2 to add,+ createfor both resources, and(known after apply)forid, the checksums,file_idandterraform_data.output. - Run
terraform show tfplan. Expect the same actions without executing them. Note that this file now contains the full configuration and values. - Run
terraform apply tfplan. ExpectApply complete! Resources: 2 added, 0 changed, 0 destroyed, then afile_idoutput. - Verify independently:
cat hello.txtreturns the configured sentence;ls -l hello.txtshows mode0644;shasum -a 256 hello.txtmatchescontent_sha256;terraform state listshows both addresses;terraform outputshowsfile_id. - Run
terraform plan -detailed-exitcode; expectNo changes. Your infrastructure matches the configuration.and exit status0. - Edit
contentto"Hello from Terraform, second draft.", runterraform plan -out=replace.tfplan, and expect-/+,must be replacedand# forces replacement. Apply the plan; expect1 added, 0 changed, 1 destroyed, andcat hello.txtshows the new sentence. Theidchanges. - Edit
terraform_data.revision.inputto"draft-2", plan with-out=update.tfplan; expect~ update in-placeand0 added, 1 changed, 0 destroyedafter apply. Theidstays the same andoutputis recomputed. Plan again; expect no changes and exit0. - Run
terraform plan -destroy -out=destroy.tfplan, inspect it withterraform show destroy.tfplan, thenterraform apply destroy.tfplan. Expect0 added, 0 changed, 2 destroyed. - Confirm the end state:
terraform state listprints nothing;ls hello.txtfails;terraform.tfstatecontains"resources": [];.terraform/, the lock file, the source files, the backup and the plan files remain.
Expected observation. Four plan summaries tell the whole story: 2 to add for creation, 1 to add / 1 to destroy for a replacement, 0 to add / 1 to change for an in-place update, and 2 to destroy for cleanup. The final no-change plan is the evidence that the last apply converged.
Failure checks. A mistyped provider version stops init with no available releases match the given constraints. A modified lock hash stops installation with a checksum error naming the provider. Deleting hello.txt by hand makes the next plan propose + create, not an error. Applying a saved plan after another operation fails with Saved plan is stale. Deleting .terraform makes the next plan stop with Required plugins are not installed and tell you to run terraform init.
Cost dimensions. Zero provider or cloud charges: the provider writes local files and the built-in control object only stores a value in state. The real costs are the one-time downloads and disk: on darwin_arm64 the CLI was a 34 MB archive and a 118 MB installed binary, and the provider was 17 MB. Plans, state and backup are kilobytes. No network calls occur after init.
Cleanup. Step 9 removes the file and clears the resources. Then delete the scratch directory, which removes .terraform/, the lock file, state, backup and all plan files. Confirm with ls that no hello.txt exists outside the lab. There is no cloud inventory to audit.
References (verified 5 November 2026):
terraform init: https://developer.hashicorp.com/terraform/cli/commands/initterraform plan, markers,-out,-detailed-exitcode: https://developer.hashicorp.com/terraform/cli/commands/planterraform apply, saved plan mode: https://developer.hashicorp.com/terraform/cli/commands/applyterraform destroy: https://developer.hashicorp.com/terraform/cli/commands/destroy- Dependency lock file: https://developer.hashicorp.com/terraform/language/files/dependency-lock
local_fileresource, schema defaults: https://registry.terraform.io/providers/hashicorp/local/2.9.1/docs/resources/file- Terraform releases, CLI 1.17.1: https://releases.hashicorp.com/terraform/
- Terraform state and sensitivity: https://developer.hashicorp.com/terraform/language/state
Next in the Series
In From One Server to a Load-Balanced Web Service, we'll explore Build a bounded AWS sandbox deployment and separate infrastructure creation from service readiness.