← rhash

Terraform — Lesson 1: Your First Run

Prototype

The lab terminal is a high-fidelity simulation of the Terraform CLI — it behaves like the real CLI for everything in this lesson. A real apply against AWS would need a cloud account; this lesson needs none.

Lesson 1

Your First Terraform Run

Clicking works—until you must do it again

Imagine you build a server by clicking through a cloud dashboard. It works perfectly. A week later, a teammate needs the same setup in another region. Which options did you choose? Which security rule came first? One forgotten click can leave the second server different from the first.

Think of cooking without a written recipe. The first dish may turn out well, but repeating it depends on memory. A written recipe gives you something you can review, improve, share, and use again. Infrastructure needs the same kind of repeatable instructions.

That is the problem Terraform solves. Terraform is an infrastructure as code tool: you describe the infrastructure you want in human-readable configuration files instead of rebuilding it from memory. Those files can be reviewed, versioned, reused, and shared like application code.

Infrastructure can be compute, storage, networks, DNS records, or features in other services. Terraform manages those objects through their APIs and follows the same configuration throughout their lifecycle.

Never let the crew start before you see the plan

A repeatable file solves one problem, but it creates another: what if a change in that file replaces the wrong server or removes something important? You need to see the consequences before anything happens.

Imagine building a house. The configuration is the architect’s blueprint. Before anyone lifts a hammer, the contractor slides an itemized proposal across the table: “Here is what I will build, what I will change, and what I will tear down.” Only after you approve it does the crew begin.

Terraform turns that rhythm into three steps: Write → Plan → Apply.

1. WriteDescribe the resources you want in configuration files.
2. PlanPreview the exact changes Terraform proposes.
3. ApplyApprove the plan and let Terraform perform it.

Write what you want. Plan to see what will change. Apply only after you review it. The plan compares your configuration with existing infrastructure and shows what will be created, updated, or destroyed. Apply then performs the approved operations in dependency order.

One tool must speak to many platforms

A server may live in AWS, a DNS record somewhere else, and a repository in GitHub. Their APIs do not all speak the same language. Terraform needs a way to communicate with each one without becoming a completely different tool every time.

Picture a traveler working with local interpreters. The traveler keeps one way of expressing the goal; each interpreter translates that goal into the language understood locally.

In Terraform, that interpreter is called a provider. A provider is a plugin that translates Terraform configuration into API calls for a platform such as AWS, Azure, Google Cloud, Kubernetes, or GitHub.

The individual object in the work order—a virtual machine, DNS record, or repository—is called a resource. Terraform tracks and manages each resource through its provider.

How does Terraform know what already exists?

Now imagine you return to the project next month. The configuration says what should exist, and the cloud contains what actually exists. Terraform must know which real object belongs to which line of configuration before it can safely calculate the next change.

Think of an as-built ledger. A blueprint records the intention; the ledger records what was actually installed. When work resumes, the crew compares both instead of guessing.

Terraform calls that ledger state. State maps your configuration to real-world objects, helping Terraform decide what already exists and what must change to make reality match the files.

Practice the workflow without a cloud bill

Your first practice run should not require AWS credentials, a provider download, or the risk of creating something chargeable. You need the Terraform lifecycle without the external infrastructure.

Think of a flight simulator. You practice the sequence and the decisions before a real aircraft—or a real cloud resource—is involved.

For this lesson, that simulator is the built-in terraform_data resource. It follows Terraform’s normal resource lifecycle but performs no other real-world action. It accepts an input, stores the value in state, and exposes it as output after apply.

That lets you practice the real init → plan → apply → destroy sequence with zero cost and zero setup.

The order matters more than memorizing commands

Imagine walking into a workshop and switching on every machine at random. Even if you know each button, the job will go wrong. Terraform commands also have a sequence: prepare the workspace, inspect the proposed work, approve it, read the result, and clean up.

terraform initPrepare the working directory. Run it first after writing a new configuration; it is safe to run again.
terraform planCalculate and show the changes Terraform proposes.
terraform applyShow a plan, ask for approval, and perform the approved changes.
terraform outputRead output values from state.
terraform destroyPlan and remove all resources managed by the current configuration.
validate · fmt · state · versionCheck validity, format files, inspect state, and identify the CLI version.

Write what you want. Plan to see what will change. Apply only after you review it. Keep that sentence in mind; you will follow it in the lab.