Terraform Basics
Providers, resources, and the plan-then-apply workflow that makes infrastructure changes predictable.
On this page4 sections
Terraform is the most widely used tool for infrastructure as code, and works across every major cloud provider through the same core workflow and syntax.
Providers and resources
A Terraform file (written in HCL, HashiCorp Configuration Language) names a provider - which platform it's talking to - and then declares resources on it:
provider "aws" {
region = "us-east-1"
}
resource "aws_instance" "web" {
ami = "ami-0123456789"
instance_type = "t3.micro"
}
This says, in full: "talk to AWS's us-east-1 region, and there should exist one t3.micro instance running this AMI, which I'll refer to elsewhere in this config as aws_instance.web."
The core workflow
terraform init # download the provider plugin, set up the working directory
terraform plan # show exactly what would change - a dry run
terraform apply # actually make those changes
terraform destroy # tear everything this config created back down
terraform plan is the step that makes this trustworthy: it prints precisely what will be created, changed, or destroyed, and nothing actually happens until apply is run and confirmed. No surprises between "what I expected" and "what happened."
Reading a plan
Terraform marks every line of a plan with a symbol - + to create, - to destroy, ~ to update in place. A plan that shows an unexpected - (destroying something you didn't mean to touch) is exactly the kind of mistake this dry-run step exists to catch before it becomes real.
Try it
cat main.tf
When you're ready, hit Mark complete and move to the next lesson.
Challenge
View the contents of main.tf.
Want to experiment first? Try things in the practice terminal (opens in a new tab), then enter the command that solves the task here.
Quiz
Lock in the concepts. Score at least 80% to mark the lesson complete.
Done with this one?
Skipped the challenge? You can mark the lesson complete by hand.