Write your first HCL, then run the core loop every Terraform project lives by — init, plan, apply, destroy — using local providers so you need no cloud account.
Why: you describe the infrastructure you WANT in files written in HCL (HashiCorp Configuration Language), and Terraform makes reality match. A block has a type (resource, provider…), labels, and a body of arguments. This whole course uses providers that need no cloud account — start with local_file, which just writes a file to disk.
# main.tf
terraform {
required_providers {
local = {
source = "hashicorp/local"
version = "~> 2.5"
}
}
}
resource "local_file" "hello" {
filename = "hello.txt"
content = "Hello, Terraform!"
}terraform init reads your configuration, downloads the providers it needs into a .terraform directory, and writes a lock file pinning their versions. Run it once per project and again whenever you add a provider or module. Nothing is created yet — this only prepares the working directory.
Download providers and prepare the working directory
terraform initterraform plan compares your configuration against what currently exists and prints exactly what it would do — a "+" for create, "~" for change, "-" for destroy. It changes nothing. Reading the plan before every apply is the habit that keeps Terraform safe.
Show what would happen, without doing it
terraform planterraform apply shows the plan again and waits for you to type "yes" before making changes. After it runs, the local_file resource exists — check that hello.txt is really on disk. Terraform now records what it created in a state file (the next lessons go deep on state).
Apply the changes (prompts for confirmation)
terraform applyThe file now exists — see for yourself
cat hello.txtterraform destroy removes everything in the configuration — the mirror image of apply. It also prompts for confirmation. For throwaway practice this resets you to a clean slate; in production it is exactly as dangerous as it sounds, so read what it lists first.
Remove everything this configuration created
terraform destroy