Start with a Working Example: One Root Module, One Child Module
Before learning the vocabulary, build something small enough to inspect. This example uses HashiCorp's local provider to write a text file, so it needs no cloud account, credentials, or billable infrastructure. The example has two Terraform files:
main.tfis the root module: it declares the provider, calls a child module, and exposes the file path as an output.modules/greeting/main.tfis the child module: it declares an input, one resource, and an output.
Create an empty working directory, save both HCL blocks at the paths shown, and run the Bash commands from that directory. The example uses no cloud account or credentials.
Read the configuration from the outside in. The root module passes a string into module.greeting, and the child receives it as var.message. A file resource writes the value, then the child's path output returns the filename to the root module for display.
That is what the word module means here: a directory of Terraform configuration. A module can accept inputs, declare resources, and return outputs. A child module does not contain a special kind of Terraform code; it is ordinary HCL that Core loads into the same configuration graph.
A provider has a different job. The configuration names hashicorp/local, and the provider supplies the local_file resource type and the code that creates, reads, and deletes files. The provider is installed separately from Terraform itself. In this example it acts on the local filesystem; an AWS provider would instead implement AWS resource types and communicate with AWS APIs.
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel tspan, .edgeLabel span, .edgeLabel p, .edgeLabel div { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#f8f9fa','tertiaryTextColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart LR
ROOT["Root module
main.tf"] -->|"module source"| CHILD["Child module
modules/greeting"]
ROOT --> CORE["Terraform Core
loads and plans configuration"]
CHILD --> CORE
CORE -->|"provider protocol"| PROVIDER["hashicorp/local
provider plugin"]
PROVIDER -->|"writes and reads"| FILE["greeting.txt
local filesystem"]
CORE --> STATE["State
address and attributes"]
classDef primary fill:#132440,color:#ffffff,stroke:#0b172b;
classDef secondary fill:#16476A,color:#ffffff,stroke:#0f314a;
classDef ok fill:#3B9797,color:#ffffff,stroke:#2a6f6f;
class ROOT,CORE,STATE primary;
class CHILD,PROVIDER secondary;
class FILE ok;
Three different jobs
Configuration describes; Core coordinates; the provider acts. The module is more configuration for Core to read. Core evaluates it and builds a plan. The provider supplies the resource type and performs the operation on its system. You can learn the boundary without first learning Go or connecting to a cloud account.
Follow the Example Through init, plan and apply
Each command has one job: init installs the provider, fmt formats the HCL, validate checks the configuration and provider schema, plan proposes a change, and apply asks for approval before writing the file and recording the result. Validation does not create the file.
The root file tells Core which provider it needs and where the child module lives. Core reads both modules and evaluates the input. The provider schema defines which arguments the file resource accepts, so validation can catch a misspelled name or wrong type before anything is written.
The plan uses the Terraform address module.greeting.local_file.greeting. It combines the module call, resource type, and resource name to identify the configured resource; it is not the file path itself.
%%{init: {'theme':'base','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#f8f9fa','tertiaryTextColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
A["terraform init"] --> B["Install provider
and prepare directory"]
B --> C["Core loads root
and child modules"]
C --> D["Validate against
provider schema"]
D --> E["terraform plan
propose one file"]
E --> F{"Approve apply?"}
F -->|"no"| G["No file is written"]
F -->|"yes"| H["Core asks provider
to create resource"]
H --> I["Provider writes
greeting.txt"]
I --> J["Core records result
in state"]
classDef primary fill:#132440,color:#ffffff,stroke:#0b172b;
classDef secondary fill:#16476A,color:#ffffff,stroke:#0f314a;
classDef ok fill:#3B9797,color:#ffffff,stroke:#2a6f6f;
classDef danger fill:#BF092F,color:#ffffff,stroke:#7a0420;
class A,C,E,F primary;
class B,D,H secondary;
class G danger;
class I,J ok;
The plan should show one resource to add, with the address module.greeting.local_file.greeting. The abbreviated output below is representative; the absolute file path depends on where you created the lab. The important point is that Terraform shows the proposed action before asking the provider to write anything.
The provider is responsible for the file operation, but Core owns the workflow around it: reading the configuration, validating the arguments, deciding the resource address, presenting the proposed change, and updating state after the provider returns. With a cloud provider, that same sequence applies, but the provider calls a remote API and errors may involve credentials, permissions, quotas, or network failures. This local lab does not exercise those cloud-specific conditions.
State Connects a Terraform Address to the File
The address module.greeting.local_file.greeting and the path modules/greeting/greeting.txt answer different questions. The address says which configured resource this is. The path is the identity the local provider uses for the file it manages. State keeps the association so the next plan can ask, “What does this configured address currently correspond to?”
After apply, terraform state list shows the tracked address and terraform state show displays stored resource details. State also holds provider-returned values such as the filename and content hash. If you change the message and apply again, Terraform keeps the same address while the provider updates the file.
State is not a backup
State helps Terraform manage objects; it does not preserve their contents as a recovery copy. State can contain values you would not want exposed, so protect it and use a remote backend with access controls and locking when a team shares it. The file created by this lab is separate from the state file.
For this local-only exercise, the default local state file is terraform.tfstate. Do not commit that file, .terraform/, or saved plan files to a source repository. A shared team configuration should use a supported remote backend so collaborators can coordinate state and locking; the next Terraform lessons build on that topic.
One writer per state file
Two applies must not write the same state snapshot at once. A backend with locking coordinates writers; without it, concurrent runs can overwrite each other's recorded results even when the provider successfully changed the real objects.
References Build a Dependency Graph
Terraform does not execute files from top to bottom. It reads all .tf files in a module as one configuration and builds a graph from references between values and resources. File names help people organize code; they do not set resource order.
In the example, the root output references module.greeting.path, and that child output references local_file.greeting.filename. Those references tell Core which value depends on which resource. Terraform can therefore wait for the provider's result before calculating the output. This is also why the resource address contains a module path: it records where the resource was declared in the configuration tree.
A resource can depend on another by using one of its values. For example, make a receipt file's content include the greeting file's path. Core sees that reference and orders the greeting write before the receipt write; without a relationship, it may run both in parallel. Use an explicit dependency only when the relationship cannot be expressed through a value.
References are the dependency language
Prefer a real value reference over a guessed order. When one resource needs an attribute from another, write that reference and let Terraform infer the edge. Add depends_on only for an important ordering dependency that has no usable attribute to reference.
A Plan Is a Proposal Under Current Assumptions
A plan answers: “Given this configuration, the state I just read, and the values available now, what would Terraform try to change?” For the local-file exercise, the path and content are already known, so the plan can show the proposed file creation. A cloud resource may return a generated address only after creation; that value appears as (known after apply) and any resource depending on it must wait.
A plan is not a reservation. It does not reserve cloud quota, lock a remote API against manual edits, or guarantee that credentials will still have permission when apply runs. A provider may fail after some earlier operations succeeded. If the real environment changes between plan and apply, review a fresh plan rather than assuming the older proposal still describes the situation.
A plan is evidence, not a reservation
Review the proposed actions, then apply deliberately. The plan is based on the configuration, state, and observations available at that time. Terraform Core coordinates the work, the provider attempts each operation, and the platform or local system decides whether it succeeds.
The foundation is now concrete: the module contributes configuration, the provider contributes a resource type and implementation, Core builds the graph and plan, references express order, and state connects a Terraform address to the object the provider manages. The same model applies to a cloud server, database, DNS record, or local file; only the provider and the system it talks to change.
Next in the Series
In Install Terraform and Make the Toolchain Reproducible, we'll explore Install a verified CLI, select compatible versions and keep local and CI environments aligned.