Friday, April 18, 2025

💻 What Is Infrastructure as Code? (And Why You Should Care If You’re Building on Azure)

Programming Language💻 What Is Infrastructure as Code? (And Why You Should Care If You're Building on Azure)


Hey everyone 👋

If you’re getting into cloud, DevOps, or anything involving deploying software infrastructure, you’ve probably heard the term infrastructure as code (IaC) thrown around. When I first heard it, I thought it sounded like something only enterprise-level teams used. But as I’ve been working more with Azure, it turns out IaC is one of the most helpful ways to keep your deployments clean, consistent, and repeatable — no matter your project size.

Let me explain it the way I wish someone had explained it to me early on 👇


🧸 Think of It Like an Instruction Manual (for Your Cloud)

Let’s say your company designs cool new toys. Each toy needs to be assembled, and every box comes with an instruction manual.

Now imagine that your cloud infrastructure — your storage accounts, virtual machines, networks — is like a toy set. Infrastructure as code is the instruction manual for setting everything up.

But instead of physical parts and screwdrivers, your manual is written in code (like JSON or Bicep). And instead of following it by hand, you give it to Azure, and Azure builds it for you. Automatically. Accurately. Every. Time.


⚙️ Why Use Infrastructure as Code (IaC)?

IaC gives you some pretty awesome powers:

✅ 1. Confidence in Your Deployments

When you hand-code things through the Azure Portal, it’s easy to forget a step. With IaC, your instructions are written once, tested, and reused. No guessing if things are configured correctly.

You can:

  • Run security scans on your code before it gets deployed.
  • Use version control (like Git) to track changes.
  • Review everything through pull requests — just like your application code.

🌍 2. Manage Many Environments Easily

Need a dev, test, and production environment? Just tweak a few parameters, and boom — spin them up with the same setup.

It’s like making a cake: same recipe, but different frosting for each occasion 🎂

💥 3. Avoid “Configuration Drift”

Ever had prod and staging environments behave differently — even though they’re “the same”? That’s configuration drift. IaC solves that by ensuring the same code deploys the same resources every time — thanks to a concept called idempotence.

Run the same script 5 times? It’ll only make changes if something needs to change.


💬 How You Write IaC: Imperative vs Declarative

There are two approaches to writing infrastructure instructions:

👟 Imperative: The Step-by-Step Recipe

You tell Azure exactly how to build your environment, like:

az group create ...
az vm create ...
Enter fullscreen mode

Exit fullscreen mode

Great for scripting. But as things grow, managing all the steps becomes overwhelming.

🗺️ Declarative: The Final Result

You describe what you want, not how to get there:

{
  "type": "Microsoft.Storage/storageAccounts",
  "name": "mycoolstorage",
  "properties": {
    ...
  }
}
Enter fullscreen mode

Exit fullscreen mode

Azure handles the order and execution. You just define the end state. Way easier to manage, especially at scale.


🎯 What Is Azure Resource Manager (ARM)?

Azure uses something called Azure Resource Manager (ARM) to take your templates and turn them into real-world infrastructure.

ARM handles:

  • Control plane actions like creating resources
  • Data plane actions like connecting to those resources
  • Security and access control
  • Validation before deploying anything

You can send ARM instructions using:

  • Azure Portal (manually)
  • Azure CLI / PowerShell (imperative)
  • ARM templates or Bicep (declarative)

🧾 JSON vs Bicep Templates

JSON was the original way to write ARM templates. It works, but it’s… verbose. Writing JSON by hand can feel like solving a Rubik’s cube blindfolded.

Enter Bicep — a new, simpler, Azure-native language for defining infrastructure.

Compare this:

JSON:

"resources": [
  {
    "type": "Microsoft.Storage/storageAccounts",
    "apiVersion": "2023-05-01",
    "name": "[parameters('storageName')]",
    ...
  }
]
Enter fullscreen mode

Exit fullscreen mode

Bicep:

resource storageAccount 'Microsoft.Storage/storageAccounts@2023-05-01' = {
  name: storageAccountName
  ...
}
Enter fullscreen mode

Exit fullscreen mode

Cleaner, right? You also get:

  • Autocomplete in VS Code
  • Built-in validation
  • Automatic dependency management

🧠 When Should You Use Bicep?

Use Bicep if:

  • You’re deploying mostly to Azure
  • You want a cleaner alternative to JSON
  • You’re working with CI/CD pipelines
  • You like readable code

Avoid Bicep if:

  • You’re managing multi-cloud (AWS, GCP, etc.)
  • Your team already uses tools like Terraform

But for Azure-only projects? Bicep is a dream.


🧩 Final Thoughts

Infrastructure as code isn’t just for enterprise teams anymore. It’s for anyone who wants their cloud resources to be:

  • Easy to reproduce
  • Version controlled
  • Reliable across environments

If you’re learning Azure, ARM templates, or Bicep, I’m right there with you — figuring it out, one line at a time.

Want to chat about your own journey or share cool IaC tips? Drop me a message on LinkedIn — would love to connect with others building cool stuff in the cloud ☁️💬

Check out our other content

Check out other tags:

Most Popular Articles