DEV Community

Cover image for Day 1 - Introduction to Infrastructure as Code (IaC)
ankitgadling
ankitgadling

Posted on • Edited on

Day 1 - Introduction to Infrastructure as Code (IaC)

Why IaC is needed

When you do big or repetitive tasks by hand, it’s easy to mess something up or forget a step. IaC helps by letting you write your infrastructure as code, so everything is repeatable, automated, and way less error-prone. Plus, it saves money because you can create resources only when you need them and delete them right after.
Example: A developer can run a single command to build a temporary AWS environment for a demo, and remove it as soon as the demo ends so no charges keep adding up.


Common IaC Tools

  • Terraform (HashiCorp)
  • AWS CloudFormation
  • Pulumi

What is Terraform?

Terraform is an open-source Infrastructure as Code (IaC) tool that allows you to define, preview, and apply infrastructure changes across many different cloud and on-prem providers. It lets teams manage resources using configuration files instead of manual steps.


HashiCorp Configuration Language (HCL)

Terraform uses HCL, a human-friendly configuration language that:

  • Looks similar to JSON but has its own cleaner syntax
  • Is designed to be easy to read and write
  • Supports variables, modules, and expressions

How Terraform Works (High-Level Overview)

  1. Write configuration files (.tf) to describe the infrastructure you want (e.g., VMs, networks, storage).
  2. Run terraform init Initializes the working directory, downloads required providers and modules.
  3. Run terraform plan Shows the changes Terraform will perform creating, modifying, or deleting resources.
  4. Run terraform apply Executes the plan, provisioning or updating resources and saving the state.
  5. Run terraform destroy Cleans up and removes the infrastructure when it’s no longer needed.

Terraform communicates with cloud platforms through providers, which handle API calls and ensure resources are created, updated, or deleted in the correct order based on dependencies.


Top comments (0)