Thuta Learning
BasicDevOpsintermediate

Creating Your First Resource

Relax. We'll talk through this in plain words — no textbook voice.

What you'll walk away with

  • Understand Creating Your First Resource, no intimidation required
  • Get hands-on running terraform commands and HCL code yourself
  • Be ready to apply this concept in a real project right away

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

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

resource "local_file" "greeting" {
  filename = "${path.module}/hello.txt"
  content  = "Hello, Terraform!"
}
You should see
$ 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.

Easy traps

  • Running `terraform apply` directly without `terraform init` first — you'll get an error since the provider plugin isn't there yet
  • Not realizing that if you edit a resource manually (outside Terraform), Terraform will treat this as 'drift' (we'll dig deeper into this in the drift lesson later)

Now try it yourself

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`.

You'll know it worked when: $ terraform apply local_file.greeting: Creating... local_file.greeting: Creation complete after 0s Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

Creating Your First Resource | Thuta Learning