Let's think about this for a second
A resource represents each individual 'thing' that Terraform creates and manages — a server, a database, a file, a DNS record — every resource type falls under this concept. You use the syntax `resource "<type>" "<local_name>"` and write arguments (config details) inside the block. Terraform records in the state file that 'this resource has already been created,' so the next time you run `apply` (with no changes), it won't do anything further.
Let's connect this to a real scenario
After `terraform apply`, you'll actually see a file called `hello.txt` appear on disk — if you edit the content and run `apply` again, Terraform will detect the change and update the file. Running `terraform destroy` deletes every Terraform-managed resource — this command matters a lot for cleaning up after each practice session.
Let's look at an example
terraform {
required_providers {
local = {
source = "hashicorp/local"
version = "~> 2.5"
}
}
}
resource "local_file" "greeting" {
filename = "${path.module}/hello.txt"
content = "Hello, Terraform!"
}$ terraform apply
local_file.greeting: Creating...
local_file.greeting: Creation complete after 0s
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.5-minute try-it
Save the code above as a file and run `terraform init && terraform apply` — once you've confirmed `hello.txt` appeared, clean up with `terraform destroy`.
A quick word of caution
`terraform destroy` deletes resources irreversibly — be extremely careful before running destroy against production state.