Your first configuration with local resources

Beginner · 10 min

Write a first Terraform project that manages files on your own disk, so you can learn the files, the loop and the state with no cloud account and no bill.

Before thisInstalling and pinning Terraform and OpenTofu

Jeff Brown Tech · 28 min · from 7:22

Your first configuration with local resources

The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.

Taught by Jeff Brown TechReport a problem with this video
Not started
Set this lesson's status

What you'll learn

  • Terraform does not care whether a resource is a cloud server or a text file. The `local` provider manages files, which makes it a free place to learn.
  • A project is a folder of `.tf` files. Terraform reads them all together, so splitting into `main.tf`, `variables.tf` and `outputs.tf` is a convention for readers, not a rule.
  • Each resource has a type, a local name, and arguments. Its attributes, such as `id`, become available to other blocks once it exists.
  • Terraform's state records the file it made. Delete the file by hand and the next plan wants to create it again.

Learn the loop before the cloud

Most first Terraform tutorials start by asking you to create a cloud account, make an access key and launch a server. That puts three unrelated problems in front of the thing you came to learn: credentials, billing and a provider you have not met. You end up debugging an IAM error on day one.

Terraform is not special about clouds. A resource is anything a provider can create, read, update and delete. The local provider treats a file on your disk as such a thing. That is enough to see every part of the workflow, with nothing to pay for and nothing to clean up except a folder.

The smallest project

Make an empty directory and put this in main.tf. It is written from the local provider docs. I did not run it, since there is no Terraform on this machine:

terraform {
  required_providers {
    local = {
      source  = "hashicorp/local"
      version = "~> 2.5"
    }
  }
}

resource "local_file" "greeting" {
  filename = "${path.module}/out/greeting.txt"
  content  = "hello from terraform\n"
}

output "greeting_id" {
  value = local_file.greeting.id
}

Walk through it block by block.

  • The terraform block declares which providers the folder needs and from where. hashicorp/local is the provider’s source address. The ~> 2.5 constraint is explained in a later lesson.
  • resource "local_file" "greeting" has a type (local_file, which tells Terraform which provider owns it) and a local name (greeting, which exists only inside your code). Together, local_file.greeting is the resource’s address. You will see that string in every plan.
  • Inside the braces are arguments. The provider docs say filename is required, and that exactly one of content, content_base64 or source must be given. ${path.module} expands to the folder holding this file.
  • The output block prints a value after apply. It also shows how references work: local_file.greeting.id reads an attribute, a value the provider reports once the resource exists.

Run the usual loop and you get out/greeting.txt with one line in it. The video clip shows this style of project being created and applied, with the workflow commands that the next lesson covers properly.

What id means here

The provider docs describe id as “the hexadecimal encoding of the SHA1 checksum of the file content”, and list content_sha256 and others as read-only attributes. I checked the idea on the same text by hand, since there is no Terraform to ask:

$ printf 'hello from terraform\n' > hello.txt
$ shasum -a 1 hello.txt
2ffa7f6c49f636710e6b30e1e7763d32ba20f678  hello.txt
$ shasum -a 256 hello.txt
49d388d7e12cfcb61f52ae908947fe5dd37cb8f6af229de911d21636c4877120  hello.txt

If the docs are right, greeting_id would print that SHA1 value. This is shasum computing it, not Terraform printing it, so treat it as a prediction you can verify on your own machine. Change one character in content and the id changes with it, which is why the resource is a good one to watch in a plan.

Files in a project

After init, a project folder holds:

  • main.tf and any other .tf files, all read as one configuration. A common split is main.tf for resources, variables.tf for inputs and outputs.tf for outputs. Terraform does not require it.
  • .terraform/, where init downloads providers. Do not commit it.
  • .terraform.lock.hcl, the provider lock file. Do commit this one.
  • terraform.tfstate, the state file, once you apply. It holds the record that local_file.greeting created that particular file. Do not commit it either.

A typical .gitignore for a Terraform repo lists .terraform/ and *.tfstate*. State gets a whole group of lessons later in this roadmap, starting with inside the state file.

Try breaking it

The real learning comes from poking it. Three experiments, each safe on a text file:

  1. Change content and run plan. You should see one resource marked for update or replacement, with the old and new value.
  2. Delete out/greeting.txt yourself and run plan again. Terraform should propose creating it, because state says it exists and reality says it does not.
  3. Run apply twice in a row. The second should report no changes, because the code, state and disk agree.

The provider docs add a warning that explains experiment two. They say that on a new machine, where the file is missing, Terraform detects the resource as deleted and shows a diff to recreate it. That is noise for a file, and a clue about why local-file resources are a poor fit for team projects. They also set the default file_permission to "0777", so set it yourself if the file should not be world-writable.

About the video

The embed is Jeff Brown Tech’s “Terraform for Beginners | Easy Tutorial to Get Started” from November 2025, from “Terraform Project Files” through “Deploying Terraform Project”, 7:22 to 17:50. Its description says it deploys simple local resources. I judged the content from that description and the chapter list. The code above is mine, so it may differ from the video’s. The channel is small, with a few thousand views. English was judged from title, channel and English auto-captions.

Where this fits

You have a file on disk and a state file recording it. The next lesson slows down and looks at each command in the loop: init, validate, plan, apply and destroy in practice.

Check yourself

  1. 01You create `main.tf` and `outputs.tf` in one folder. In what order does Terraform read them?

    It does not matter. Terraform loads every `.tf` file in the directory as one configuration and orders work by references between blocks, not by file or line.

  2. 02After `apply`, you delete the file the `local_file` resource created and run `plan`. What happens and why?

    The plan proposes creating it again. State says the resource exists, the provider reports that the file is gone, and Terraform closes the gap between code and reality.

  3. 03Why is a `local_file` project a good first exercise, and what is one way it differs from real infrastructure?

    It needs no account and costs nothing, but it runs on your disk. The provider docs warn that applying on a new machine, where the file is missing, shows a diff to recreate it, which real cloud resources would not.

Go deeper

Notes

Private to you

Esc
↑↓ navigate↵ open? shortcuts

Keyboard shortcuts

Press Esc to close

Anywhere

⌘K
Search and commands
/
Search
?
This sheet
Esc
Close

Reading a lesson

J
Next lesson
K
Previous lesson
B
Bookmark