In the pre-cloud era, setting up a new application environment required a system administrator to sit down, follow a 20-page runbook, and manually click through menus or execute terminal scripts. This manual approach caused configuration drift (where staging and production silently diverged) and snowflake servers (one-of-a-kind servers that nobody knows how to rebuild if they crash). Infrastructure as Code (IaC) treats your infrastructure with the exact same rigor as application code—version-controlled in Git, peer-reviewed via pull requests, and tested in CI/CD pipelines.
There are two fundamentally different approaches to writing Infrastructure as Code:
| Feature | Declarative Approach (The "WHAT") | Imperative Approach (The "HOW") |
|---|---|---|
| Core Philosophy | You define the desired end state of the infrastructure. The engine figures out the step-by-step diff to achieve it. | You write step-by-step procedural commands telling the system exactly how to configure resources sequentially. |
| Idempotency | Inherently Idempotent. Running the template 10 times results in the exact same state without duplicate resources. | Hard to maintain idempotency. Running a bash script twice might create duplicate virtual machines or crash on port conflicts. |
| State Tracking | Maintains an explicit state file to detect deleted or modified resources. | Typically stateless; executes commands blindly against targets. |
| Industry Tools | Terraform, AWS CloudFormation, Azure Bicep, Kubernetes YAML. | Bash scripts, Python Boto3 scripts, AWS CLI, Ansible (procedural). |
apply when 3 subnets already exist will do nothing (zero changes).plan stage and automatically revert manual unauthorized changes back to the declared code state.Broaden your enterprise cloud architecture and DevOps expertise across our curriculum:
Master the multi-cloud declarative HCL language used by thousands of engineering organizations.
Compare cloud-native infrastructure code tools tailored specifically for AWS and Azure ecosystems.
Embed security scanning tools (Checkov, tfsec) into IaC code to catch misconfigurations before deployment.
Core interview questions on declarative vs imperative IaC, state locking, and configuration drift.