Click through the AWS console to create one server and it takes five minutes. Do the same for a VPC, two subnets, a security group, a load balancer and three servers, then repeat it for a staging copy, and you will see why teams stopped doing it by hand. Terraform lets you describe that infrastructure in a few text files, review it like code and rebuild it in one command.
The short answer: Terraform is an infrastructure-as-code tool. You write what you want (a VPC, a server, a bucket) in HCL files, run terraform plan to see what will change, and terraform apply to make it happen. Learn it after Linux, Git and basic AWS, and expect a week or two of practice before it feels natural.
Terraform is part of month three in our DevOps training in Pune, right after containers and CI/CD. This guide covers what you need before your first real project.
What problem Terraform solves
Without infrastructure as code, a cloud setup lives in someone’s memory and in a long trail of console clicks. Nobody can say exactly how production was built, staging slowly drifts away from it, and rebuilding after a mistake takes days.
With Terraform, the setup lives in a Git repository. A change to a security group becomes a pull request that a teammate reviews. The plan shows exactly what will be created, changed or destroyed before anything happens. And when you need a second environment, you reuse the same code with different variables.
The four ideas you need first
Providers
A provider is a plugin that talks to one platform’s API. The aws provider creates AWS resources, the azurerm provider handles Azure, and there are providers for Kubernetes, GitHub, Cloudflare and hundreds more. You declare which providers you need, and terraform init downloads them.
Resources
A resource is one thing you want to exist: an EC2 instance, an S3 bucket, a DNS record. Each resource block has a type, a name you choose, and its settings.
State
Terraform keeps a state file that maps your code to the real resources it created. This is how it knows that aws_instance.web is a particular server ID. Lose or corrupt the state and Terraform forgets what it manages, so handling state carefully is the most important habit to build.
Variables and outputs
Variables let one piece of code serve several environments, such as a small instance type in dev and a larger one in production. Outputs print useful values after an apply, like a server’s public IP.
Your first Terraform file
Here is a minimal example that creates one EC2 instance in the Mumbai region. Save it as main.tf in an empty folder:
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
}
}
provider "aws" {
region = "ap-south-1"
}
variable "instance_type" {
default = "t3.micro"
}
resource "aws_instance" "web" {
ami = "ami-xxxxxxxx" # pick a current Amazon Linux AMI
instance_type = var.instance_type
tags = { Name = "terraform-demo" }
}
output "public_ip" {
value = aws_instance.web.public_ip
}
Then run the four commands you will use every day:
terraform init # download the AWS provider
terraform plan # preview: 1 to add, 0 to change, 0 to destroy
terraform apply # create it (type yes to confirm)
terraform destroy # remove everything this code created
Change instance_type to t3.small and run plan again. Terraform shows an in-place update instead of a new server. Reading plans like this, and spotting when a change would destroy and recreate something, is a skill interviewers test directly.
Mistakes beginners make
- Committing the state file to Git. State can hold passwords and keys. Add
*.tfstateto.gitignorefrom day one. - Keeping state only on a laptop. Once a team is involved, store state in a remote backend such as an S3 bucket with locking turned on, so two people cannot apply at the same time.
- Skipping the plan. Always read the plan before applying, especially lines marked
-/+, which mean destroy and recreate. - Editing resources in the console. Manual changes create drift, and the next apply may undo them. If Terraform manages it, change it in code.
- Forgetting to destroy practice resources. Run
terraform destroyat the end of every practice session to avoid a surprise cloud bill.
Terraform, Ansible and CloudFormation
These tools are often confused. Terraform creates and changes infrastructure across many platforms. Ansible is mainly for configuring what runs on servers, such as installing packages and editing config files. CloudFormation does a similar job to Terraform but only on AWS. Many Pune teams use Terraform to build servers and Ansible to configure them, which is why both appear in job descriptions.
You may also see OpenTofu, an open-source fork created after HashiCorp changed Terraform’s licence in 2023. The language and commands are nearly identical, so what you learn transfers directly.
A two-week practice plan
- Days 1 to 3: install Terraform, create and destroy a single EC2 instance and an S3 bucket. Read every plan.
- Days 4 to 7: build a VPC with public and private subnets, a security group and a server. Use variables and outputs.
- Days 8 to 10: move state to an S3 backend with locking. Split repeated code into a small module.
- Days 11 to 14: run Terraform from a CI pipeline so a pull request shows the plan, then deploy your app onto the new infrastructure.
That last step turns into a strong portfolio piece. Our list of DevOps projects for your resume shows how to combine it with Docker and Kubernetes. If you are still choosing a cloud, read AWS vs Azure for DevOps jobs in Pune first, and see the DevOps roadmap for freshers for where Terraform fits in the bigger picture.
Frequently asked questions
Do I need to know programming to learn Terraform?
No. HCL is a configuration language, closer to a structured settings file than to Python or Java. If you can read YAML or JSON, you can read Terraform. Basic scripting helps once you automate it in pipelines.
Should I learn Terraform or Ansible first?
Terraform first, if you are working with cloud. You need infrastructure before you can configure it. Ansible is quick to pick up afterwards, and many projects use both together.
Is Terraform asked in DevOps interviews in Pune?
It appears in many mid-level DevOps job descriptions, so expect questions about state, plan versus apply, modules and how you handle secrets. Being able to explain a project you built with it matters more than memorising syntax.
Will practising Terraform on AWS cost money?
Small practice setups can stay within or close to the AWS free tier if you pick small instance types and destroy everything after each session. Set a billing alert before you start.





