Day 9 – Infrastructure as Code (IaC) with Terraform & Ansible

Day 1 of a 26-day 'Zero to Hero' guide for becoming a DevOps Engineer in 2025. The title asks 'What is DevOps? A Beginner's Guide for 2025' and includes concepts related to CI/CD pipelines, infrastructure, and automation, though some terms contain typographical errors.

Introduction

In today’s DevOps world, Infrastructure as Code (IaC) has changed the way engineers manage and set up IT infrastructure.

Instead of manually configuring servers and networks, IaC lets teams define everything using code—making deployments consistent, repeatable, and easy to scale.

At CuriosityTech.in, we focus on teaching IaC not just for automation, but to help build strong, cloud-native environments.


What is Infrastructure as Code (IaC)?

IaC means using code (instead of manual steps) to manage and create infrastructure.

It helps DevOps teams to:

  1. Automate setup and configuration
  2. Keep environments consistent (dev, test, prod)
  3. Reduce mistakes and downtime
  4. Track changes using version control (like Git)

Think of IaC as a blueprint written in code—every server, database, and network is described clearly, either declaratively or imperatively.


Types of IaC

IaC TypeDescriptionExample Tools
DeclarativeYou define the end result you want. The system figures out how.Terraform, Kubernetes Manifests
ImperativeYou give step-by-step instructions.Ansible, Chef, Puppet

Terraform vs Ansible

Two popular IaC tools are Terraform and Ansible. They have different purposes but can work together.

FeatureTerraformAnsible
TypeDeclarativeImperative
Primary UseProvisioning infrastructure (VMs, networks, etc.)Configuring systems and deploying apps
State ManagementTracks state using filesStateless (depends on idempotent playbooks)
Supported PlatformsAWS, Azure, GCP, Kubernetes, VMwareLinux, Windows, network devices
Learning CurveMediumEasy to Medium
Best ForInfrastructure provisioningConfiguration and orchestration

IaC Workflow (Terraform & Ansible)

Terraform: Declarative Infrastructure Provisioning

Terraform uses HCL (HashiCorp Configuration Language) to define cloud infrastructure.

Workflow:

  1. Write Config Files – Define VMs, networks, storage
  2. Initializeterraform init to download plugins
  3. Planterraform plan to preview changes
  4. Applyterraform apply to deploy resources
  5. Manage State – Use terraform.tfstate to track changes

Example – AWS EC2 instance:

provider "aws" {
  region = "us-east-1"
}

resource "aws_instance" "web_server" {
  ami           = "ami-0c94855ba95c71c99"
  instance_type = "t2.micro"

  tags = {
    Name = "WebServer"
  }
}

At CuriosityTech.in, learners start by provisioning VMs and networks in AWS or GCP using Terraform.


Ansible: Imperative Configuration Management

Ansible is a simple, agentless tool for configuring systems and deploying apps. It uses YAML playbooks that are easy to read and write.

Workflow:

  1. Install Ansible – pip install ansible
  2. Define Inventory – List of servers
  3. Write Playbooks – Define tasks in YAML
  4. Run – ansible-playbook site.yml

Example – Install Nginx:

- hosts: webservers
  become: yes
  tasks:
    - name: Install Nginx
      apt:
        name: nginx
        state: present

    - name: Start Nginx
      service:
        name: nginx
        state: started

Best Practices for IaC

  1. Use Version Control (Git) – Track changes
  2. Start Small – One VM or container
  3. Combine Terraform + Ansible – Provision with Terraform, configure with Ansible
  4. Test Changes – Use staging before production
  5. Ensure Idempotency – Scripts should run multiple times without breaking anything

At CuriosityTech.in, students do hands-on labs to simulate real-world DevOps work.


Challenges & Solutions

ChallengeSolution
Large Environment ComplexityUse modules in Terraform and roles in Ansible
Managing StateStore state remotely (e.g., AWS S3 for Terraform)
Learning CurveStart small, grow complexity step-by-step
Configuration DriftReapply playbooks regularly to keep systems aligned

End-to-End IaC Pipeline (Infographic Summary)


Conclusion

Infrastructure as Code (IaC) helps DevOps teams manage cloud infrastructure efficiently. Tools like Terraform and Ansible make it easier to automate and scale deployments.

To master IaC, engineers need:

  • Knowledge of both declarative and imperative approaches
  • Hands-on experience in cloud environments
  • Integration into CI/CD pipelines

At CuriosityTech.in, we train learners to provision, configure, and manage real cloud infrastructure using these tools—so they’re ready for enterprise DevOps roles.

By practicing real-world scenarios, engineers gain the skills to build scalable, secure, and reliable systems from the ground up.

Leave a Comment

Your email address will not be published. Required fields are marked *