DEV Community

Omkar Sharma
Omkar Sharma

Posted on

Guide For Starting Terraform

omkarsharma2821

Without Infrastructure as Code, creating infrastructure is a task. With Terraform, it becomes a repeatable process.

Imagine you are asked to create infrastructure for a new application/project.

You need:

  • A VPC
  • Subnets
  • Route tables
  • Security groups
  • EC2 instances
  • Load balancers
  • Databases
  • IAM roles
  • Monitoring

You open the cloud console and start creating everything manually.

The first environment takes a few hours.

Then someone asks:

"Can we create the same infrastructure for staging?"

So you start again.

Then production.

Then another region.

Then six months later, someone asks:

"What exactly did we change in the infrastructure?"

And now the real problem begins.

You might remember some of it.

Maybe you have documentation.

Maybe someone took screenshots.

Maybe you have a spreadsheet.

Or maybe you simply say:

"I don't remember. I created it manually."

This is where Terraform changes the way we think about infrastructure.

What Is Terraform?

Terraform is an Infrastructure as Code (IaC) tool that allows you to define and manage infrastructure using configuration files instead of manually creating resources through a cloud console.

Instead of saying:

"Go to AWS → VPC → Create → Subnet → Create → Security Group → Create..."

You define what you want in code.

For example:

resource "aws_instance" "web" {
  ami           = "ami-xxxxxxxx"
  instance_type = "t2.micro"

  tags = {
    Name = "web-server"
  }
}
Enter fullscreen mode Exit fullscreen mode

Terraform reads this configuration and creates the infrastructure for you.

The important part isn't just that Terraform creates an EC2 instance.

The important part is that your infrastructure is now represented as code.

And code can be:

  • Version controlled
  • Reviewed
  • Reused
  • Tested
  • Shared
  • Automated
  • Recreated

That's where the real value comes from.

What Happens If We Don't Use Terraform?

Let's look at the traditional approach.

Suppose a company has three environments:

Development
     ↓
Staging
     ↓
Production
Enter fullscreen mode Exit fullscreen mode

Someone manually creates resources in each environment.

Over time, small differences start appearing.

Development might have:

EC2: t3.micro
Security Group: Port 80, 22
Subnet: 10.0.1.0/24
Enter fullscreen mode Exit fullscreen mode

Staging might have:

EC2: t3.small
Security Group: Port 80, 443, 22
Subnet: 10.0.2.0/24
Enter fullscreen mode Exit fullscreen mode

Production might have:

EC2: t3.medium
Security Group: Port 80, 443
Subnet: 10.0.10.0/24
Enter fullscreen mode Exit fullscreen mode

Some differences are intentional.

Others might simply be mistakes.

This creates the famous problem:

"It works in my environment."

The application may work in development but fail in staging because the environments aren't configured the same way.

Terraform helps solve this by making the infrastructure configuration repeatable and standardized.

1. Save Time

One of the biggest benefits of Terraform is simple:

Automation saves time.

Imagine manually creating:

  • 1 VPC
  • 4 subnets
  • 2 route tables
  • 3 security groups
  • 5 EC2 instances
  • 1 load balancer
  • 1 database

Doing this manually can take considerable time.

Now imagine you need the same infrastructure again.

With Terraform, you don't start from zero.

You can reuse your configuration.

terraform init
terraform plan
terraform apply
Enter fullscreen mode Exit fullscreen mode

That's it.

Instead of repeatedly clicking through the cloud console, you let Terraform perform the repetitive work.

Write once. Deploy many times.

2. Reduce Human Errors

Humans make mistakes.

It's normal.

Maybe someone:

  • Selects the wrong subnet
  • Opens the wrong security group port
  • Chooses the wrong instance type
  • Attaches the wrong route table
  • Forgets to enable encryption
  • Creates a resource in the wrong region

One small mistake in infrastructure can cause a major problem.

Terraform doesn't eliminate every possible mistake, but it significantly reduces manual configuration errors by making infrastructure configuration explicit and repeatable.

Instead of relying on memory:

"I think I configured production the same way."

You have code that defines exactly what should exist.

3. Environment Consistency

This is one of my favorite benefits of Infrastructure as Code.

Consider:

Development
     ↓
Staging
     ↓
Production
Enter fullscreen mode Exit fullscreen mode

Without IaC, each environment can slowly become different.

With Terraform, you can define a standard infrastructure architecture and reuse it across environments.

For example:

terraform/
│
├── modules/
│   ├── network/
│   ├── compute/
│   └── database/
│
├── environments/
│   ├── dev/
│   ├── staging/
│   └── production/
Enter fullscreen mode Exit fullscreen mode

The exact values can differ between environments, but the infrastructure structure can remain consistent.

This helps eliminate:

"It works on my machine."

And moves toward:

"It works because every environment follows the same infrastructure definition."

4. Repetitive Tasks Become Automation

Think about how many times DevOps engineers perform the same tasks.

Create a:

  • VPC
  • Subnet
  • Security group
  • IAM role
  • EC2 instance
  • Load balancer

Doing these things repeatedly is not a great use of engineering time.

Terraform turns repetitive infrastructure tasks into reusable code.

Instead of:

Click
Click
Click
Configure
Verify
Repeat
Enter fullscreen mode Exit fullscreen mode

You move toward:

Code
   ↓
Plan
   ↓
Apply
   ↓
Infrastructure
Enter fullscreen mode Exit fullscreen mode

Your time can then be spent on more valuable engineering problems instead of repetitive clicking.

5. Write Once, Deploy Many

This is where Terraform becomes extremely powerful.

Suppose you've created a network architecture using Terraform.

You can reuse it for:

Development
Staging
Production
DR
Testing
New Region
New Project
Enter fullscreen mode Exit fullscreen mode

You don't need to recreate everything manually.

You can parameterize your configuration using variables.

For example:

variable "environment" {
  type = string
}

variable "instance_type" {
  type = string
}
Enter fullscreen mode Exit fullscreen mode

Then different environments can provide different values.

dev        → t3.micro
staging    → t3.small
production → t3.medium
Enter fullscreen mode Exit fullscreen mode

The infrastructure logic remains reusable.

6. Infrastructure Changes Become Trackable

Here's another major problem with manually created infrastructure:

Who changed what?

Imagine someone modifies a production security group.

You discover the change two weeks later.

Who changed it?

Why?

When?

What was the previous configuration?

With Terraform, your infrastructure configuration can live in Git.

For example:

Git Repository
      │
      ├── Commit 1
      ├── Commit 2
      ├── Commit 3
      └── Commit 4
Enter fullscreen mode Exit fullscreen mode

Now infrastructure changes can go through the same process as application code:

Developer
   ↓
Change Terraform code
   ↓
Git commit
   ↓
Pull Request
   ↓
Code Review
   ↓
Terraform Plan
   ↓
Terraform Apply
Enter fullscreen mode Exit fullscreen mode

Infrastructure becomes part of your software development lifecycle.

7. Terraform Plan: See Before You Change

One of the most useful Terraform commands is:

terraform plan
Enter fullscreen mode Exit fullscreen mode

It shows what Terraform intends to change before actually making those changes.

For example:

Plan: 2 to add, 1 to change, 0 to destroy.
Enter fullscreen mode Exit fullscreen mode

This gives you an opportunity to review infrastructure changes before applying them.

Instead of:

"I clicked something and now production changed."

You get:

"Here is exactly what Terraform plans to change."

That makes infrastructure changes much more predictable.

8. Easier Infrastructure Maintenance

Infrastructure isn't something you create once and forget.

It changes constantly.

You might need to:

  • Upgrade an instance
  • Add a subnet
  • Modify security rules
  • Add a load balancer
  • Change database configuration
  • Add monitoring
  • Update networking

Without IaC, these changes can become difficult to track.

With Terraform, you modify the configuration.

For example:

instance_type = "t3.micro"
Enter fullscreen mode Exit fullscreen mode

can become:

instance_type = "t3.medium"
Enter fullscreen mode Exit fullscreen mode

Terraform can determine the required change.

Your infrastructure configuration becomes the source of truth for the desired state.

9. Easier Disaster Recovery

Imagine your infrastructure is accidentally deleted.

If everything was created manually, rebuilding it could take hours or even days.

If your infrastructure is defined in Terraform:

Terraform Code
      ↓
terraform apply
      ↓
Infrastructure recreated
Enter fullscreen mode Exit fullscreen mode

You can recreate the infrastructure from the configuration.

Of course, production recovery also requires proper backups, state management, secrets management, data recovery strategies, and testing.

Terraform isn't a backup system.

But it can make rebuilding infrastructure dramatically easier.

10. Save Engineering Cost

Terraform itself doesn't magically make your cloud bill cheaper.

But it can help reduce costs indirectly.

How?

Less manual work

Engineers spend less time repeatedly creating infrastructure.

Fewer configuration mistakes

Incorrect configurations can lead to unnecessary resource usage.

Easier cleanup

Temporary environments can be destroyed when they're no longer needed.

terraform destroy
Enter fullscreen mode Exit fullscreen mode

For example:

Testing Environment
       ↓
Create
       ↓
Run Tests
       ↓
No longer needed
       ↓
terraform destroy
Enter fullscreen mode Exit fullscreen mode

This is much better than leaving forgotten resources running and discovering them later on the cloud bill.

11. Infrastructure Lifecycle Becomes Simple

Terraform can help manage the infrastructure lifecycle:

Provision
    ↓
Maintain
    ↓
Modify
    ↓
Scale
    ↓
Destroy
Enter fullscreen mode Exit fullscreen mode

Provision

terraform apply
Enter fullscreen mode Exit fullscreen mode

Create infrastructure.

Maintain

Modify Terraform configuration and apply changes.

Destroy

terraform destroy
Enter fullscreen mode Exit fullscreen mode

Remove infrastructure that is no longer required.

The entire lifecycle can be managed through code.

12. Multi-Cloud Infrastructure

Another major advantage is that Terraform supports many infrastructure providers.

For example:

             Terraform
                 │
       ┌─────────┼─────────┐
       ↓         ↓         ↓
      AWS       Azure      GCP
Enter fullscreen mode Exit fullscreen mode

You can use Terraform to manage resources across different providers.

This doesn't mean you should always use multiple clouds.

It simply means your infrastructure tooling doesn't have to be tied to a single cloud platform.

13. Terraform Fits Naturally Into CI/CD

Terraform becomes even more powerful when combined with CI/CD.

For example:

Developer
    ↓
Git Push
    ↓
CI/CD Pipeline
    ↓
terraform fmt
    ↓
terraform validate
    ↓
terraform plan
    ↓
Approval
    ↓
terraform apply
    ↓
Infrastructure
Enter fullscreen mode Exit fullscreen mode

Now infrastructure changes can follow an automated workflow.

You don't necessarily need someone sitting in front of the cloud console.

Terraform Isn't Just About Creating Resources

This is probably the most important point.

Terraform isn't valuable simply because it can create an EC2 instance.

You could create an EC2 instance manually.

You could also use a cloud CLI.

The real value is:

Terraform turns infrastructure into code.

And once infrastructure becomes code, you gain:

Version Control
       +
Automation
       +
Consistency
       +
Reusability
       +
Reviewability
       +
Repeatability
       +
Reduced Human Error
Enter fullscreen mode Exit fullscreen mode

That's the real benefit.

Manual Infrastructure vs Terraform

Manual Approach Terraform
Click through console Infrastructure as Code
Repetitive work Automation
Higher human error Consistent configuration
Difficult to reproduce Easily reproducible
Harder to track changes Git version control
Environment drift Standardized environments
Manual documentation Code acts as documentation
Difficult to scale Reusable configuration
Manual cleanup terraform destroy
Harder collaboration Code review + Git
Time-consuming Faster provisioning

But Should Everything Be Terraform?

Not necessarily.

Terraform is powerful, but it's not a magic solution for everything.

You still need to think about:

  • Terraform state management
  • Secrets management
  • State locking
  • Module design
  • Provider versions
  • Access control
  • CI/CD security
  • Infrastructure testing
  • Cloud architecture

And you should avoid blindly putting every manual action into Terraform.

The goal isn't:

"Use Terraform because everyone uses Terraform."

The goal is:

Use Infrastructure as Code when repeatability, consistency, automation, and controlled infrastructure changes matter.

The Real Shift

Without Infrastructure as Code, the process often looks like this:

Human
  ↓
Cloud Console
  ↓
Manual Configuration
  ↓
Infrastructure
Enter fullscreen mode Exit fullscreen mode

With Terraform:

Engineer
    ↓
Terraform Code
    ↓
Git
    ↓
Review
    ↓
Terraform Plan
    ↓
Terraform Apply
    ↓
Infrastructure
Enter fullscreen mode Exit fullscreen mode

That's a fundamental change in how infrastructure is managed.

So instead of infrastructure being something that engineers manually build, Terraform allows infrastructure to become something engineers define, review, reproduce, and automate.

And that's why Infrastructure as Code has become such an important part of modern DevOps.

Write once. Review once. Deploy repeatedly.


✍️ Author: Omkar Sharma

📬 Feel free to connect on LinkedIn or explore more on GitHub

Top comments (0)