Back to Terraform

Read Terraform Configuration: Blocks, Files and the Root Module

November 5, 2026 Updated November 17, 2026 Wasil Zafar 28 min read

Understand the native HCL structure and the directory that Terraform treats as one configuration

Table of Contents

  1. Read a Block Without Memorizing a Whole Language
  2. All Configuration Files in a Directory Form One Module
  3. Separate Settings, Providers, Resources and Outputs
  4. Format Code for Review Instead of Personal Taste
  5. When JSON Syntax and Override Files Are Appropriate
  6. Turn an Untidy Configuration into a Readable Root

Read a Block Without Memorizing a Whole Language

Read HCL from the outside in. In a header such as resource "local_file" "hello", resource is the block type, local_file is the provider-defined object type, and hello is Terraform's local name for this object. Inside the braces, arguments such as filename and content configure the file. Braces group settings that belong together. You can understand and edit a small configuration without learning every HCL feature first.

A colleague hands you a directory and asks what it will build. There is no entry point file, no main() function and no top-to-bottom script. Start with one main.tf so you can see the whole configuration; later, the same blocks can be split across conventional .tf files without changing what Terraform builds.

The language looks stranger than it is. Terraform configuration is written in HCL, the HashiCorp Configuration Language. Its native syntax is designed for people to read and review; a JSON variant exists for programs to generate. Both describe the same objects, and both reduce to a small set of shapes. Once you can name the parts of one block, you can read most Terraform code the way you read a form: find the heading, then work through the fields.

Every construct in native syntax is a block or an argument. A block has a type, zero or more quoted labels, and a body inside braces. An argument is a name, an equals sign and an expression, written inside a body. That is the whole grammar you need to start.

The example below is a complete root module in one file. It creates a local text file, so you can read the block structure and try the commands without a cloud account. Use an empty scratch directory: terraform apply writes motd.txt there, and terraform destroy removes the file.

terraform {
  # The terraform block has no labels. This argument constrains the CLI.
  required_version = "1.17.1"

  # This nested block declares which provider plugin the module needs.
  required_providers {
    local = {
      # `local` is an argument; its value is an object with two attributes.
      source  = "hashicorp/local"
      version = "2.9.1"
    }
  }
}

# This block has one label: the provider's local name. Its body can be empty.
provider "local" {}

# A variable block has one label and describes an input to this module.
variable "message" {
  description = "Text to write into the local message file."
  type        = string
  default     = "Hello from my first Terraform module."
}

# A locals block has no labels; its body defines named expressions.
locals {
  message_file = "${path.module}/motd.txt"
}

# A resource block has two labels: provider-defined type, then your local name.
resource "local_file" "motd" {
  filename        = local.message_file
  content         = var.message
  file_permission = "0644"
}

# An output block has one label and can expose a resource attribute.
output "motd_path" {
  description = "Path of the file managed by this configuration."
  value       = local_file.motd.filename
}
# Run these commands from the directory containing main.tf.
terraform init
terraform validate
terraform plan
terraform apply
terraform output motd_path
terraform destroy

Now read the script from the outside in. terraform, provider, variable, locals, resource and output are block types. The quoted text after some types is a label: local names the provider, message names the variable, local_file and motd identify the resource, and motd_path names the output. terraform and locals have no labels. A resource's type and labels form its address, local_file.motd.

Inside a block body, required_version, description, filename and value are arguments: each is a name, equals sign and expression. required_providers is a nested block inside terraform. By contrast, local = { ... } is an argument whose value is an object. Its source and version entries are attributes of that object, not separate blocks. The braces after required_providers open a block body; the braces after local = construct a value.

The values also show three common expression forms. "Hello ..." and "0644" are literal strings; the leading zero is why the file mode is written as text. "${path.module}/motd.txt" is a string template that builds a path relative to this module. local.message_file, var.message and local_file.motd.filename are references to values defined elsewhere in the configuration. Terraform follows those references to determine what depends on what.

Run terraform init to install the declared provider, validate to check the configuration, and plan to review the proposed local file. apply writes the file after confirmation; output prints the path; destroy removes the managed file. The commands operate on the configuration as a whole, not on individual files or blocks.

A repeatable way to decode any block:

  1. Block type. The keyword before the first label or brace. It selects the schema: terraform, provider, resource, data, variable, output, locals, module, moved. The schema decides which arguments and nested blocks are legal.
  2. Labels. Quoted identifiers whose count depends on the block type. A resource takes two, a provider, variable, output or module takes one, and terraform or locals takes none.
  3. Body. Arguments and nested blocks. Argument order inside a body does not change behaviour, with a few ordered exceptions such as multiple provisioner blocks.
  4. Expressions. Every argument value is evaluated. A quoted string is a template, so "${path.module}/motd.txt" interpolates the module path; in the root module path.module is ".", so a plan renders ./motd.txt. A bare reference such as local_file.motd.filename reads an attribute. Terraform also supports collection constructors, conditionals such as var.enabled ? 1 : 0, and function calls, which later articles cover.
  5. Comments. # is the idiomatic form and comments out the rest of the line; repeat it on consecutive lines for a longer note. // and /* ... */ are accepted for compatibility, but the style guide discourages them.

A nested block is simply a block inside a body. required_providers inside terraform, and lifecycle inside a resource, are the first two you will meet. A nested block may carry its own labels, as provisioner "local-exec" does, and it may contain arguments and further blocks. Its braces belong to the nested block, not to the parent argument list.

Figure 1 separates the header decisions from the body decisions. Figure 2 draws the same block as nested regions: the outer boundary is the block, the argument and nested block are regions inside the body, and only the nested block has a body of its own.

Read a Block Without Memorizing a Whole Language
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','titleColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','activationBorderColor':'#132440','signalColor':'#5a6e82','signalTextColor':'#132440','noteBkgColor':'#c4873b','noteTextColor':'#132440','noteBorderColor':'#132440','labelBoxBkgColor':'#a8dede','labelBoxBorderColor':'#132440','labelTextColor':'#132440','loopTextColor':'#132440','altBackground':'#f8f9fa','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
    A["One block in a .tf file"] --> B["Header: type plus labels"]
    A --> C["Body inside braces"]
    B --> B1["Type: resource"]
    B --> B2["Labels: local_file, motd"]
    C --> C1["Arguments: name equals expression"]
    C --> C2["Nested blocks: required_providers, lifecycle"]
    C --> C3["Comments: hash plus explanation"]
    C1 --> D["Expressions produce values"]
    D --> D1["Literal: 0644"]
    D --> D2["Reference: local_file.motd.filename"]
    D --> D3["Template: path.module/motd.txt"]
    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;
    classDef warn fill:#c4873b,color:#132440,stroke:#8a5a1f;
    class A,D primary;
    class B,C secondary;
    class B1,B2,C1,C2,C3 ok;
    class D1,D2,D3 warn;
The parts of one Terraform block A resource block has a navy header with its type and two labels. Its body contains a teal argument and an amber nested block. The argument is a name and an expression. The nested block has its own braces and its own body. One block, read from the outside in resource "local_file" "motd" { block type and two quoted labels body filename = "${path.module}/motd.txt" argument: name = expression lifecycle { create_before_destroy = true } Header block type plus quoted labels Body arguments and nested blocks Argument name = expression Nested block a block with its own body Braces bound a body; a nested block sits inside a body.
Configuration

Read a Block Without Memorizing a Whole Language

Execution status: design-only. This is a reading exercise; nothing here needs a cloud account or a command.

Read the HCL panel from top to bottom and annotate the configuration by hand. You can do this exercise without a cloud account, credentials or a Terraform installation.

  1. Circle every block type. Underline each quoted label. Box each argument name.
  2. Mark each expression as one of: literal, reference, string template, collection, conditional or function call.
  3. Draw a second set of braces around any nested block, and label it separately from the argument braces.
  4. Read the local_file.motd block aloud as a sentence: "This is a resource of type local_file, named motd, with a filename built from the module path, literal content, and a permission string."
  5. Explain why local = { ... } inside required_providers is an argument rather than a block.

Expected observation. You should be able to point at required_providers as a nested block, local = { ... } as an argument with an object value, and source, version, filename, content and file_permission as arguments. The ${...} in the local path is a template, not a block.

Failure check. If you cannot decide whether a pair of braces opens a body or builds a value, look at what precedes it. A block type and optional labels precede a body; an equals sign precedes a value.

Cost and cleanup. Zero. Delete the annotations, or keep them as a reading aid for the next article.

All Configuration Files in a Directory Form One Module

Terraform does not care which file a block lives in. A module is a collection of .tf and .tf.json files kept together in one directory. Terraform parses every file and evaluates the result as a single document. Splitting blocks across files is for readers and maintainers; it has no effect on behaviour.

When you run terraform plan in a directory, that directory is the root module. The complete configuration is the root module plus every child module it calls, directly or indirectly. In the CLI the root module is simply the working directory. In HCP Terraform or Terraform Enterprise it defaults to the top of the configuration directory, though a workspace can point at a subdirectory.

Filenames do not impose execution order. Terraform does not run versions.tf, then providers.tf, then main.tf as if they were steps in a script. It gathers the blocks, builds a dependency graph from references, and plans against that graph. The value = local_file.motd.filename in outputs.tf creates an edge from the output to the resource no matter which file each one lives in. Two unrelated resources have no ordering relationship at all.

This is why the four-file example is still one module. versions.tf supplies the toolchain constraints, providers.tf configures the provider, main.tf declares the file, and outputs.tf exposes a value. A reader moves between them for convenience; Terraform reads them together.

Subdirectories are not included. A modules/motd/main.tf file is a different module until a module block names it, for example module "motd" { source = "./modules/motd" }. Resources inside then receive addresses prefixed with module.motd., and the child's outputs must be re-exported if the root is to expose them. Child modules are covered properly in a later article; the point here is that directory nesting alone includes nothing.

Duplicate definitions are an error rather than a merge. If two files define resource "local_file" "motd", Terraform reports a duplicate configuration error instead of silently picking one. That is a safety feature: the file layout may be arbitrary, but an object address must be unique within a module.

Not every file in the directory is configuration. A .tfvars file supplies variable values, a .tfstate file is the state record, .terraform.lock.hcl records provider selections, and .terraform/ is a local cache. Only .tf and .tf.json files participate in the module. The files overview states the rule plainly: a module consists of the top-level configuration files in a directory, and nested directories are separate modules.

Figure 3 draws the boundary. The dashed region is the root module; the four files feed one evaluation; the child module sits outside until a module block reaches it. Figure 4 follows the loading mechanics, including the two common failure branches: a parse error and a duplicate block.

A root module is a directory, not a file Four files inside a dashed directory boundary feed one configuration evaluation. Filenames do not set an order. A modules subdirectory sits outside the boundary and is included only by an explicit module block. A directory is the module; files are pages root module: one directory, read as one configuration versions.tf pins the CLI and provider providers.tf provider settings and aliases main.tf resources and data sources outputs.tf values printed after apply one configuration all .tf and .tf.json files are parsed together, not in filename order modules/motd/ is a child module separate files, separate addresses only an explicit module block includes it
All Configuration Files in a Directory Form One Module
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','titleColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','activationBorderColor':'#132440','signalColor':'#5a6e82','signalTextColor':'#132440','noteBkgColor':'#c4873b','noteTextColor':'#132440','noteBorderColor':'#132440','labelBoxBkgColor':'#a8dede','labelBoxBorderColor':'#132440','labelTextColor':'#132440','loopTextColor':'#132440','altBackground':'#f8f9fa','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
    A["terraform plan in a directory"] --> B["Read every .tf and .tf.json file"]
    B --> C{"Every file parses?"}
    C -->|"no"| C1["Error names the file and line"]
    C -->|"yes"| D{"Same type and labels twice?"}
    D -->|"yes"| D1["Error: duplicate configuration"]
    D -->|"no"| E["Apply override files in lexical order"]
    E --> F["Evaluate the directory as one document"]
    F --> G["Build the dependency graph"]
    G --> H["Plan the root module"]
    B -.-> X["Subdirectories are separate modules"]
    X -.-> X1["Only a module block includes a child"]
    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;
    classDef warn fill:#c4873b,color:#132440,stroke:#8a5a1f;
    class A,F,G,H primary;
    class B,C,D,E secondary;
    class X,X1 ok;
    class C1,D1 danger;

The practical consequence cuts both ways. You can split a module for readability without changing what it builds. You cannot hide a resource from Terraform by moving it into a subdirectory; you can only take it out of the module entirely, or leave it in a directory that no module block references.

Separate Settings, Providers, Resources and Outputs

Four filenames carry most of the convention in a root module. None of them is required, and Terraform does not reward the names with special treatment beyond loading them like any other configuration file.

  • versions.tf holds the terraform block: required_version and required_providers. In the example it pins the CLI to 1.17.1 and the provider to hashicorp/local version 2.9.1.
  • providers.tf holds provider blocks and their aliases. The example's provider "local" {} is deliberately empty; an AWS provider block would carry a region and default tags here.
  • main.tf holds resource and data source blocks. Here it contains resource "local_file" "motd" with filename, content and file_permission.
  • outputs.tf holds output blocks. Here it contains output "motd_path" with a description and value = local_file.motd.filename.

HashiCorp's current style guide calls the first file terraform.tf rather than versions.tf. Both names are in wide use, and the series uses versions.tf because the next article does. The name is a convention, not a keyword. What matters is that the terraform block is easy to find when someone needs to change a constraint.

Other conventions appear as the module grows. variables.tf holds input variable blocks, locals.tf holds named expressions, and backend.tf holds the backend or cloud configuration that decides where state lives. A single main.tf containing all of these blocks is perfectly valid. The reason to split is review and ownership: a provider upgrade touches versions.tf, a new object touches main.tf, and a reviewer can classify the change before reading the diff.

There is a cost to splitting too early. A small root module with one resource per file is harder to read than one file, because the reader follows references across tabs for no benefit. Split when a file stops fitting on a screen, when different people own different capabilities, or when a generated file must be kept separate from hand-written code. At that point, group by capability rather than by resource type: network.tf, compute.tf, storage.tf, with main.tf for the module's primary object.

Naming follows the same logic. A resource label should be a descriptive noun with underscores, and it should not repeat the resource type: motd, not local_file_motd, because the address already reads local_file.motd. An output should describe the value, not its position: motd_path, not output1. Within a block, put required arguments first, optional arguments next and nested blocks last. Put meta-arguments such as count and for_each before ordinary arguments, and lifecycle last. This is the order the style guide recommends, and it is the order a reviewer expects.

Format Code for Review Instead of Personal Taste

Formatting arguments are usually a sign that a team has run out of real disagreements. Terraform's answer is to remove the choice. terraform fmt rewrites native configuration into a canonical style: two spaces per nesting level, aligned equals signs for consecutive single-line arguments, one blank line between top-level blocks, and arguments above nested blocks.

The fmt documentation is candid about the trade-off. The command is intentionally opinionated and has no configuration options, because consistency across codebases matters more than any individual preference. It applies a subset of the style guide, along with small readability adjustments. Follow the documented style even where fmt does not yet enforce it.

In the example, a hand-written block might read filename = "${path.module}/motd.txt" on one line, content="Terraform wrote this file." with no spaces around the equals sign on the next, and file_permission = "0644" on a third. After terraform fmt, the three equals signs align because the values are single-line and consecutive. A later change to content produces a one-line diff instead of a whitespace storm.

What fmt will not do is equally important. It does not reorder arguments, rename labels, split a file, add comments, sort outputs or change behaviour. It is a formatter, not a linter. terraform validate checks syntax and internal consistency but does not evaluate state; a linter such as TFLint enforces team rules. Keeping those jobs separate makes each one easier to trust.

Use terraform fmt -check -recursive -diff in continuous integration. The command exits 0 when the input is already formatted and non-zero when it would change something, so a pipeline can fail on a formatting drift instead of reviewing it. Locally, plain terraform fmt rewrites files in place; -check implies no write. Run fmt after a CLI upgrade as well, because the canonical format can change in minor releases and the change is not treated as breaking.

Two habits keep formatting useful. First, keep a format-only commit separate from a behaviour change; otherwise the real diff is buried in indentation. Second, use # comments for the reason a value is unusual, not for a restatement of the value. # 0644 because the file is read by a shared service account survives review; # set file permission does not.

When JSON Syntax and Override Files Are Appropriate

Native HCL is for people. JSON is for programs. Override files are for exceptions. Confusing the three is how a readable root module becomes a puzzle.

A .tf.json file is a JSON object at the root. Each key is a top-level block type. Labels become nested objects, one level per label, and the body is the final object. The example resource therefore appears as "resource" containing "local_file", containing "motd", containing an object with "filename", "content" and "file_permission". The output appears as "output" containing "motd_path", whose "value" is the string "${local_file.motd.filename}".

Strings in expression positions are parsed as templates, so the ${path.module} interpolation keeps working. A string consisting only of one interpolation keeps the referenced value's type, which is how a JSON output can return an object rather than its string form. Comments are limited to a "//" property inside a block body; # is not valid JSON. The JSON syntax reference treats the format as a complete equivalent of native syntax, not a reduced dialect.

That equivalence is the point and the problem. JSON is the right choice when something already speaks it: an inventory system, a dashboard exporter, a migration script, a policy pipeline. Let the generator own the file, put a "//" header at the root saying what produced it and when, and commit the generator alongside the output. Do not hand-edit a generated file. Its diffs are noisy, its comments are awkward, and a human reviewer cannot see structure as quickly as in HCL.

Override files solve a narrower problem. Terraform skips any file named override.tf or override.tf.json, and any file ending in _override.tf or _override.tf.json, during the first pass. It then applies them in lexical order. A top-level block in an override merges with the block of the same type and labels. An argument replaces the argument of the same name. A nested block in the override replaces all blocks of that type in the base, and the contents of nested blocks are not merged.

The override documentation lists the exceptions. lifecycle merges argument by argument, so an override that sets create_before_destroy preserves an existing ignore_changes. Any provisioner blocks in an override replace all base provisioners. A connection block is replaced wholesale. depends_on is not allowed in an override and produces an error. Inside a terraform block, required_version is replaced entirely, required_providers merges per provider, and a backend or cloud block in an override wins over the base.

That last rule is the one to keep in mind when reading the example. Suppose the base versions.tf pins required_version = "1.17.1" and a generated versions_override.tf sets required_version = ">= 1.6". The effective constraint is >= 1.6; the exact pin is gone, not combined. Figure 5 shows the merge. A reviewer who reads only the base file will believe the toolchain is pinned when it is not.

FormWhat Terraform readsUse it whenMain risk
Native HCL (.tf)Every .tf file in the module directory, with blocks and expressions as writtenHand-written configuration, reviewable diffs, essentially all of this seriesNone specific to the format; readability still depends on file layout and naming
JSON (.tf.json)The JSON form of the same language; labelled blocks become nested objects and strings are templatesA generator already produces JSON: inventory, exporter, migration or policy toolingNo native comments, noisy hand review, and the generator can drift from the committed file
Override (override.tf, *_override.tf)The base configuration first, then each override in lexical order merged into itA generated environment patch, a time-boxed workaround, or a vendor fix that must not fork the moduleInvisible from the base file; nested blocks replace siblings wholesale; stacked overrides are order-dependent
An override replaces a value instead of adding to it A base versions file pins Terraform 1.17.1. A generated override sets the constraint to greater than or equal to 1.6. The effective configuration contains only the override constraint, so the exact pin disappears without an error. An override replaces; it does not add versions.tf (base) required_version = "1.17.1" required_providers { local = ... } an exact pin for every operator versions_override.tf required_version = ">= 1.6" generated for a CI runner no provider change effective configuration required_version = ">= 1.6" the 1.17.1 pin is gone, with no warning required_providers merges per provider Later override files win, in lexical order. Read only the base file and you will miss it.

Override files are appropriate when an exception really is exceptional and someone owns it: a platform team generating a small patch for a CI runner, a temporary workaround with a ticket and an expiry date, or a vendor module that must be adjusted without forking. They are a poor tool for routine environment differences. Use input variables and .tfvars files, separate root modules or workspaces instead; those make the difference visible in the configuration that a reviewer expects to read. An override affects only the module directory it sits in; it cannot reach into a child module's directory.

The risks are worth naming explicitly. The base file looks authoritative but is not. A nested block in an override can remove sibling blocks the author never saw. Stacked overrides depend on filename order. Automated review shows the override diff but not its effect on the base. If you must use one, add a comment in the base file pointing at the override, and add a test or plan check that fails when the effective value is unexpected.

Turn an Untidy Configuration into a Readable Root

Refactoring file layout is safe because an address does not include a filename. local_file.motd remains local_file.motd when the block moves from main.tf to site.tf, when the blocks are reordered, or when a file is renamed. Terraform re-reads the directory and derives the same address from the same type and labels. The plan is the proof: a pure layout change should produce No changes. Your infrastructure matches the configuration.

Some changes do alter addresses, and they deserve a pause:

  • Renaming either label, such as motd to message, makes the old address disappear and a new one appear. Without help, the plan proposes destroy and create.
  • Changing the resource type, such as local_file to another provider resource, does the same.
  • Adding count or for_each turns one address into indexed instances such as local_file.motd[0], which changes how existing state is matched.
  • Moving a block into a child module prefixes it with module.<name>., so the address changes even though the block itself did not.

For the last case, a moved block records the rename so Terraform can carry the state across instead of replacing the object. For a label change the shape is a moved block with from = local_file.motd and to = local_file.message. The plan then shows a move rather than a replacement. The refactoring article covers this in detail; the rule to remember now is that file layout is free, while address changes are not.

A refactor recipe that keeps the risk visible:

  1. Run terraform plan and confirm a clean baseline. Do not start from a plan that already has unrelated changes.
  2. Move blocks between files without editing arguments or labels.
  3. Run terraform fmt so the move does not also introduce whitespace changes.
  4. Run terraform plan again. Expect no changes. If Terraform proposes replacement, stop and compare the addresses rather than applying.
  5. Commit the move on its own, with a message that says it is a layout change. Then make the behaviour change in a separate commit.

At scale, organise by capability rather than by resource type. A root module for a small web service might have main.tf for the service's primary object, network.tf for the network boundary, storage.tf for buckets and permissions, and outputs.tf for the values another module or a pipeline needs. A reader should know where to look without searching. Extracting a reusable child module is a different operation from moving a block between files: it changes addresses and needs moved blocks or state surgery, which is why module design and refactoring get their own articles later.

Lab

Read and format HCL

Execution status: design-only. This card is a procedure for you to run. The article does not claim it was executed, and no results are quoted as measurements.

Prerequisites. Terraform CLI 1.17.1 available as terraform (terraform version must report it), network access to registry.terraform.io for the first init, and an empty scratch directory. The provider package is roughly 17 MB. No cloud account, credential or payment method is involved.

  1. Create motd-root/main.tf by copying the HCL panel's complete configuration. Deliberately misalign two equals signs.
  2. Run terraform fmt -check -diff. Expect a non-zero exit status and a diff limited to indentation and alignment. Confirm that no argument, label or value changed.
  3. Run terraform fmt, then terraform fmt -check again. Expect exit status 0.
  4. Annotate the file: block types, labels, arguments, expressions and nested blocks. Include one literal, one reference, one template and the object-valued local argument.
  5. Run terraform init, terraform validate and terraform plan. Expect one local_file.motd to add and an output whose value is known. Review the plan before proceeding.
  6. Move the resource block from main.tf to a new site.tf. Run terraform plan again. Expect the same address, local_file.motd, and the same one-resource proposal: filenames do not change resource identity.
  7. Run terraform apply and confirm the local file is created. Run terraform output motd_path to see the output reference resolve, then run terraform destroy and confirm that motd.txt is removed.
  8. Create a second directory motd-json/ with a .tf.json equivalent of the configuration. Run init and plan there. Expect the same one-resource proposal. Compare how each format reads to you.
  9. Back in motd-root/, add a temporary override.tf that changes content, then run plan to see the proposed file content change. Delete the override and plan again; the original value should return. Do not apply this temporary override.

Expected observation. The formatting diff contains no semantic change; moving the resource file leaves its address unchanged; output motd_path resolves to the path written by the resource; and destroying the configuration removes the file. The native and JSON directories propose the same resource address.

Failure checks. Defining the same resource in two files should fail with a duplicate configuration error, not merge. Putting the resource in a subdirectory without a module block should leave the root module with no such resource. An override that changes required_version should replace the base constraint rather than tighten it.

Cost and cleanup. Zero provider charges; the only costs are the CLI and provider downloads and a few kilobytes of local state. The lab includes terraform destroy so the managed file is removed. Delete both scratch directories when finished; if you stop before cleanup, return to motd-root/ and run terraform destroy first.

Next in the Series

In Your First Resource: Init, Plan, Apply and Destroy, we'll explore Practice the complete Terraform workflow locally before creating billable infrastructure.