DEV Community

Cristian Sifuentes
Cristian Sifuentes

Posted on

Automating Infrastructure as a Service (IaaS) in Azure with Azure CLI

Automating Infrastructure as a Service (IaaS) in Azure with Azure CLI

Automating Infrastructure as a Service (IaaS) in Azure with Azure CLI

In the world of modern cloud infrastructure, Infrastructure as a Service (IaaS) empowers teams to provision compute, network, and storage resources in a flexible and repeatable way. Microsoft Azure offers a powerful CLI that allows infrastructure engineers to build, scale, and destroy entire environments with just a few lines of Bash.

In this article, we’ll walk through a real-world automation scenario that deploys a full IaaS environment—complete with a VM, a virtual network, a subnet, and storage—and deletes it cleanly after use.


Real-World Use Case: Ephemeral Dev Environment for QA Testing

Let’s say your QA team needs a disposable virtual environment to run performance and security tests on an Ubuntu server. Rather than provisioning it manually, you automate the process so that any team member can spin it up on demand—and tear it down with equal ease.


Full Azure CLI Script

#!/bin/bash

# Step 1: Create a resource group
az group create -l eastus2 -n GrupoRecursosIaaS

# Step 2: Create a virtual machine
az vm create -n iaas-vm-amin -g GrupoRecursosIaaS --image Ubuntu2204 --admin-username aminespinoza --admin-password Am0_Apr3nd3r$

# Step 3: Create a basic storage account
az storage account create -n storageiaas004 -g GrupoRecursosIaaS -l eastus2 --sku Standard_LRS

# Step 4: Create a virtual network and subnet
az network vnet create -g GrupoRecursosIaaS -n IaaSVnet004 --address-prefix 10.0.0.0/16 --subnet-name aminesSubnet --subnet-prefixes 10.0.0.0/24

# Step 5: Optional cleanup to destroy all resources after testing
az group delete -n GrupoRecursosIaaS --force-deletion-types Microsoft.Compute/virtualMachines
Enter fullscreen mode Exit fullscreen mode

Why This Matters

This script embodies modern infrastructure principles:

  • Reusability: Run as many times as needed with predictable results.
  • Speed: Spins up infrastructure in minutes, not hours.
  • Modularity: Resources are grouped for simplified management.
  • Cost Control: Resources are deleted after use to avoid surprise billing.

Pro Tips & Best Practices

Practice Recommendation
Use strong passwords Or better: switch to SSH keys
Avoid inline credentials Use Azure Key Vault or environment variables
Automate teardown Prevent cloud bill spikes with auto-delete
Use tagging Enable cost attribution and resource tracking
Parameterize your scripts Allow dynamic naming and region selection

Expand This Use Case

Want to scale up?

  • Add network security groups for fine-grained traffic control.
  • Use ARM templates or Bicep for declarative deployments.
  • Embed this script into GitHub Actions or Azure DevOps pipelines.
  • Add Azure Monitor alerts or diagnostics.

Final Thoughts

This script is more than a few commands—it’s the gateway to a cloud-native mindset where environments are ephemeral, automation is the norm, and infrastructure becomes version-controlled and shareable.

Infrastructure-as-Code starts with one script. Start yours today.


✍️ Written by: Cristian Sifuentes – Full-stack dev crafting scalable apps with [NET - Azure], [Angular - React], Git, SQL & extensions. Clean code, dark themes, atomic commits

Top comments (1)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.