Automating Azure Infrastructure with Bicep: A Hands-On IaC Lab Using VS Code

6 min read

Deploying VNets, VMs, IAM, Policies, Monitoring, and Governance using Infrastructure as Code.

Manual infrastructure deployment does not scale in modern cloud environments. It’s not just about speed—it’s about consistency, security, and repeatability. When environments are built through one-off portal clicks, teams eventually hit the same problems:

  • Configuration drift: “Dev” and “Prod” stop matching over time.

  • Security gaps: controls get applied inconsistently (or forgotten entirely).

  • Slow change reviews: you can’t easily code review portal changes.

  • Harder governance: tagging, policy enforcement, and access control become unreliable.

Infrastructure as Code (IaC) solves this by making infrastructure declarative, version-controlled, and reproducible. In this lab, we’ll deploy a complete Azure foundation using Bicep inside Visual Studio Code, covering networking, compute, identity & access control, governance, and monitoring all through code.

Tip: Bicep is Microsoft’s recommended IaC language for Azure resource deployments. Bicep compiles to ARM templates behind the scenes, but the authoring experience is cleaner and more maintainable than raw JSON.

🎥 Video Walkthrough

What You’ll Build

This lab deploys a practical baseline environment you can reuse for real projects:

  • Resource Group to contain the environment

  • Virtual Network (VNet) and Subnets

  • Network Security Groups (NSGs) with controlled inbound rules

  • Network Interfaces

  • Windows and/or Linux Virtual Machine(s)

  • Storage Account (example of a managed PaaS resource)

  • Monitoring hooks (Log Analytics/Azure Monitor foundations)

  • Tagging strategy applied consistently via parameters

  • Governance & compliance checks via Azure Policy

  • Identity & access control via Microsoft Entra ID roles and least privilege

Architecture Diagram

If you want to strengthen your foundation before automating it, link this naturally in your intro section:

Setting Up Clean Azure VNets, Subnets & Tagging

Lab Objectives

By the end of this lab, you will be able to:

  1. Set up a local Azure IaC development environment

  2. Deploy Azure infrastructure using Bicep

  3. Implement identity and access control with Microsoft Entra ID

  4. Enforce governance with Azure Policy

  5. Apply consistent tagging across resources

  6. Validate deployments using the Azure Portal and Azure CLI

  7. Understand the “enterprise workflow” mindset for repeatable provisioning

Lab Prerequisites

  • An Azure subscription

  • Azure CLI installed

  • Visual Studio Code

  • VS Code extensions:

    • Azure Account

    • Bicep

    • ARM Template Viewer (optional, helpful for learning output ARM)

Part 1: Set Up Your IaC Development Environment

1) Install VS Code + Extensions

Install Visual Studio Code and add the extensions listed above. The Bicep extension gives you:

  • syntax highlighting

  • linting

  • autocomplete

  • template validation

  • quick fixes

2) Authenticate to Azure

Open a terminal and run:

az login 
az account show

If you manage multiple subscriptions, explicitly set the right one:

az account set --subscription "<SUBSCRIPTION_ID_OR_NAME>" 

Part 2: Create the Resource Group

Resource Groups are more than a “folder”; they’re also a lifecycle boundary (deploy, manage, and delete together).

az group create \
--name rg-iac-lab \
--location eastus

Part 3: Write and Deploy Bicep Templates

Recommended folder structure (simple but scalable)

Even for a lab, structure matters. A clean layout makes it easier to expand later:

  • main.bicep (orchestration entry point)

  • modules/ (network, compute, monitoring, storage)

  • parameters/ (optional: .json parameter files)

Example:

iac-lab/
  main.bicep
  modules/
    network.bicep
    compute.bicep
    monitoring.bicep
    storage.bicep
  parameters/
    dev.parameters.json

What your Bicep deploys

In your environment, you created Bicep for:

  • Virtual Networks & Subnets

  • NSGs

  • NICs

  • Windows & Linux VMs

  • Storage Accounts

  • Azure Monitor foundations

  • Automatic tagging

A practical approach is:

  • Put shared values in parameters (location, environment, owner, cost center).

  • Pass tags as an object so every module receives the same tagging block

Why this matters: tagging is one of the easiest ways to improve governance, cost tracking, and operational clarity.

To go deeper on governance controls, Azure Policy, Tags, and Resource Locks Explained: A Complete Governance Guide for Cloud Engineers

Deploy using:

 az deployment group create \
  --resource-group rg-iac-lab \
  --template-file main.bicep

Part 4: Identity & Access Management (IAM) with Microsoft Entra ID

Infrastructure automation is only “production-ready” when access is controlled correctly. In this lab, you used Microsoft Entra ID to:

  • manage users and groups

  • enable Privileged Identity Management (PIM)

  • use Just-In-Time (JIT) activation for elevated permissions

  • verify role activation in the Azure Portal

Why JIT/PIM matters: it reduces standing privilege. Instead of leaving “Contributor” active permanently, it’s activated only when needed, for a limited time.

If you also manage app deployments, check out Azure Web App Zero-Downtime Deployment: A Hands-On Guide to Deployment Slots, Auto Scaling, and Load Testing

Part 5: Governance with Azure Policy (and why it’s a must)

Azure Policy is how organizations enforce standards at scale. Even if your Bicep template includes tags and best practices, policy ensures that:

  • resources can’t be created without required tags

  • insecure SKUs can be restricted

  • regions can be limited

  • configurations can be audited continuously

In this lab, your validation included reviewing policy compliance status. That’s exactly the right habit—because the real question isn’t “Did it deploy?” It’s:

“Did it deploy and meet the standards we must enforce every time?”

To deepen your understanding on Azure Policy, check out Azure Policy, Tags, and Resource Locks Explained: A Complete Governance Guide for Cloud Engineers

Part 6: Monitoring and Validation (what to check after deployment)

Once deployment completes, don’t stop at the success message. Validate what matters operationally:

1) Confirm resources exist and are healthy

  • Resource Group contains expected resources

  • VM provisioning state is “Succeeded”

  • NIC attached and IP configuration correct

2) Verify tags are applied consistently

Pick a resource and confirm tags are present and correct. Consistency is the goal.

3) Check policy compliance

Navigate to Azure Policy → Compliance and confirm:

  • assignments are in effect

  • non-compliant resources are visible

  • remediation is possible (where applicable)

4) Confirm identity behavior

If you’re using PIM/JIT:

  • activate role

  • confirm permissions work only while active

  • confirm permissions drop when the activation ends

To level up monitoring as a real skill, check out How to Set Up Azure Monitor Alerts, Action Groups, and Processing Rules (Step-by-Step Guide)

Why Bicep (and when it makes the most sense)

Bicep is a strong fit in Azure-first environments because it offers:

  • Cleaner syntax than raw ARM JSON

  • Faster authoring and iteration (especially with VS Code tooling)

  • Native Azure integration (resource types, API versions, docs)

  • Modular design (reusable modules for network/compute/storage)

If you’re also building larger, multi-layer environments, your readers may like seeing Bicep used across patterns. Link this in your “Next steps” section:

Key Takeaway

Infrastructure as Code is no longer optional in cloud engineering. It’s how teams build environments that are:

  • repeatable across dev/test/prod

  • reviewable through version control

  • governed with consistent standards

  • safer to change over time

This lab demonstrates real-world Azure automation, not just theory, by combining deployment, governance, validation, and identity controls in one workflow.

Recommended Next Labs

To keep learning in a logical sequence, here are the best follow-ups:

Cleanup

To avoid ongoing cost (especially VMs), remove the resource group when finished:

az group delete --name rg-iac-lab --yes --no-wait

Discover more from Humble Cloud Tech

Subscribe to get the latest posts sent to your email.

Leave a Comment

Your email address will not be published. Required fields are marked *

We use cookies to personalise content and ads, to provide social media features and to analyse our traffic. We also share information about your use of our site with our social media, advertising and analytics partners. View more
Cookies settings
Accept
Decline
Privacy & Cookie policy
Privacy & Cookies policy
Cookie name Active

Who we are

Suggested text: Our website address is: https://humbletech.cloud.

Comments

Suggested text: When visitors leave comments on the site we collect the data shown in the comments form, and also the visitor’s IP address and browser user agent string to help spam detection. An anonymised string created from your email address (also called a hash) may be provided to the Gravatar service to see if you are using it. The Gravatar service Privacy Policy is available here: https://automattic.com/privacy/. After approval of your comment, your profile picture is visible to the public in the context of your comment.

Media

Suggested text: If you upload images to the website, you should avoid uploading images with embedded location data (EXIF GPS) included. Visitors to the website can download and extract any location data from images on the website.

Cookies

Suggested text: If you leave a comment on our site you may opt in to saving your name, email address and website in cookies. These are for your convenience so that you do not have to fill in your details again when you leave another comment. These cookies will last for one year. If you visit our login page, we will set a temporary cookie to determine if your browser accepts cookies. This cookie contains no personal data and is discarded when you close your browser. When you log in, we will also set up several cookies to save your login information and your screen display choices. Login cookies last for two days, and screen options cookies last for a year. If you select "Remember Me", your login will persist for two weeks. If you log out of your account, the login cookies will be removed. If you edit or publish an article, an additional cookie will be saved in your browser. This cookie includes no personal data and simply indicates the post ID of the article you just edited. It expires after 1 day.

Embedded content from other websites

Suggested text: Articles on this site may include embedded content (e.g. videos, images, articles, etc.). Embedded content from other websites behaves in the exact same way as if the visitor has visited the other website. These websites may collect data about you, use cookies, embed additional third-party tracking, and monitor your interaction with that embedded content, including tracking your interaction with the embedded content if you have an account and are logged in to that website.

Who we share your data with

Suggested text: If you request a password reset, your IP address will be included in the reset email.

How long we retain your data

Suggested text: If you leave a comment, the comment and its metadata are retained indefinitely. This is so we can recognise and approve any follow-up comments automatically instead of holding them in a moderation queue. For users that register on our website (if any), we also store the personal information they provide in their user profile. All users can see, edit, or delete their personal information at any time (except they cannot change their username). Website administrators can also see and edit that information.

What rights you have over your data

Suggested text: If you have an account on this site, or have left comments, you can request to receive an exported file of the personal data we hold about you, including any data you have provided to us. You can also request that we erase any personal data we hold about you. This does not include any data we are obliged to keep for administrative, legal, or security purposes.

Where your data is sent

Suggested text: Visitor comments may be checked through an automated spam detection service.
Save settings
Scroll to Top