Best Infrastructure as Code (IaaC) Samples with Real-World Explanations

Introduction

Infrastructure as Code (IaaC) has transformed how organizations deploy, configure, and manage their environments.
Instead of manual configurations, IaaC enables repeatable, secure, and scalable deployment processes — using code.

In this post, I share real-world IaaC examples that professionals can apply across cloud and on-premises environments.


1. Azure Virtual Machine Deployment using PowerShell (ARM Templates Alternative)

Scenario:
Spin up a virtual machine (VM) on Azure with custom settings — OS type, disk size, networking — in a repeatable, automated way.

Sample Command:

powershellCopyEditNew-AzVM `
  -ResourceGroupName "ProductionRG" `
  -Name "WebServer01" `
  -Location "EastUS" `
  -VirtualNetworkName "ProdVNET" `
  -SubnetName "WebSubnet" `
  -SecurityGroupName "WebSG" `
  -PublicIpAddressName "WebPublicIP" `
  -Image "Win2022Datacenter"

Explanation:
Instead of manually clicking through Azure Portal, this script launches a new production-ready VM within seconds.
This reduces human error and ensures configuration consistency.


2. On-Premises VMware VM Deployment via PowerCLI

Scenario:
Provision a Windows Server virtual machine in a vSphere datacenter using PowerShell.

Sample Command:

powershellCopyEditNew-VM -Name "SQLServer02" `
  -ResourcePool "ProductionPool" `
  -Datastore "Datastore01" `
  -Template "Win2022Template" `
  -VMHost "esxi01.mydomain.local"

Explanation:
This PowerCLI script clones a preconfigured template, attaches storage, and places the VM into a production cluster — all in one shot.
Perfect for disaster recovery planning or rapid server scaling.


3. Microsoft 365 User Creation with PowerShell

Scenario:
Automate user onboarding in Azure Active Directory + Microsoft 365.

Sample Command:

powershellCopyEditNew-MsolUser `
  -UserPrincipalName "[email protected]" `
  -DisplayName "New User" `
  -FirstName "New" `
  -LastName "User" `
  -LicenseAssignment "company:ENTERPRISEPACK"

Explanation:
Instead of manually adding users through the Microsoft 365 Admin Center, this IaaC approach ensures users are created consistently — with proper licensing attached — even in bulk.


4. Azure Resource Group + Storage Deployment with Bicep

Scenario:
Provision an entire Resource Group with a Storage Account using Bicep (Azure’s new declarative IaaC language).

Sample Bicep Code:

bicepCopyEditresource storage 'Microsoft.Storage/storageAccounts@2022-05-01' = {
  name: 'appstorage${uniqueString(resourceGroup().id)}'
  location: resourceGroup().location
  sku: {
    name: 'Standard_LRS'
  }
  kind: 'StorageV2'
}

Explanation:
Bicep simplifies complex Azure deployments.
You can version-control your cloud architecture like you would application code.


5. Automating Cisco Meraki Network Device Configuration

Scenario:
Automate bulk configuration of Meraki MX Firewalls or APs across multiple branches.

Sample API Call (Python):

pythonCopyEditimport meraki

dashboard = meraki.DashboardAPI(api_key='YOUR_API_KEY')

response = dashboard.devices.updateDevice(
    serial='Q2XX-XXXX-XXXX',
    name='Branch1-Security-Appliance',
    tags=['branch', 'security'],
    address='123 Main St, City, State'
)

Explanation:
Using APIs, infrastructure configuration is no longer limited to traditional servers.
Networking devices — switches, firewalls, access points — are now part of your automated deployments.


✨ Conclusion

Infrastructure as Code isn’t just for large enterprises — it’s for any IT professional who wants to:

  • Eliminate manual errors
  • Speed up deployments
  • Strengthen disaster recovery
  • Make infrastructure truly agile

Starting small — with a few PowerShell scripts, Bicep templates, or API automations — leads to major efficiencies over time.

© 2012–2025 Jet Mariano. All rights reserved.
For usage terms, please see the Legal Disclaimer.

error: Content is protected !!