100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Python

Infrastructure as Code

Learn how to define, version, and provision cloud infrastructure using declarative configuration files instead of manual clicks.

DevOps & Cloud OperationsIntermediate10 min readJul 8, 2026
Analogies

Introduction

Infrastructure as Code (IaC) is the practice of defining and provisioning cloud infrastructure—servers, networks, storage, and more—through machine-readable configuration files rather than manual console clicks or ad hoc scripts. Those files live in version control, so infrastructure changes go through the same review, diff, and audit process as application code.

🏏

Cricket analogy: Instead of a groundstaff member verbally instructing where to place each boundary rope, a franchise writes the stadium layout into a documented plan that's reviewed and archived, the same way IaC replaces manual console clicks with version-controlled configuration files.

Explanation

IaC tools fall into two broad approaches. A declarative approach (used by tools like Terraform, AWS CloudFormation, and Pulumi in declarative mode) lets you describe the desired end state of your infrastructure—'I want one virtual machine of this size, with this network'—and the tool figures out the steps needed to reach that state, including what to create, update, or destroy. An imperative approach (used by shell scripts or the AWS CLI) instead lists the exact sequence of commands to run—'create a VM, then attach a disk, then open a port'—and it is up to the author to keep that sequence correct as infrastructure evolves. Declarative IaC is generally preferred at scale because the tool can compute a plan, detect drift between the actual and desired state, and safely reconcile the two without the author tracking every prior action.

🏏

Cricket analogy: A declarative team-selection sheet just states 'field this XI with this batting order' and lets the support staff sort out logistics, while an imperative approach dictates each exact step of who arrives when and in what order, requiring constant manual tracking as plans change.

Example

yaml
resource "cloud_virtual_machine" "web_server" {
  name          = "web-01"
  instance_type = "small"
  region        = "us-east-1"
  image         = "ubuntu-22.04"

  network {
    vpc_id    = cloud_vpc.main.id
    subnet_id = cloud_subnet.public.id
  }

  tags = {
    environment = "production"
    managed_by  = "terraform"
  }
}

Analysis

In the example above, the configuration states what the virtual machine should look like, not the individual API calls needed to create it. Running the tool a second time with the same file produces no changes, because the actual infrastructure already matches the desired state—this property is called idempotency. If someone manually resizes the VM in the console, the next run detects that drift and offers to correct it. This declarative, version-controlled workflow is what makes IaC repeatable across environments (dev, staging, production) and safe to review through pull requests before anything is applied.

🏏

Cricket analogy: The team sheet states the desired batting order, not the exact walk-out choreography; submitting the same sheet twice changes nothing since the order's already set, but if a captain quietly swaps two batters without updating the sheet, the next review catches the discrepancy and flags it for correction.

Key Takeaways

  • IaC defines infrastructure in version-controlled, machine-readable configuration files instead of manual console actions.
  • Declarative IaC describes the desired end state; the tool computes how to get there and can detect drift.
  • Imperative IaC describes the exact steps to run, requiring the author to track state changes manually.
  • Declarative tools like Terraform are idempotent: re-running them with no changes produces no changes.

Practice what you learned

Was this page helpful?

Topics covered

#Python#CloudComputingStudyNotes#CloudComputing#InfrastructureAsCode#Infrastructure#Code#Explanation#Example#StudyNotes#SkillVeris