Modules & Parameters

💤0
Lv 10 XP
← 📜 Infrastructure as Code · Bicep

Modules & Parameters

Intermediate ⭐ 80 XP ⏱ 14 min #bicep#modules#parameters

Structure larger Bicep deployments with modules, parameter files, and decorators.

📖Theory

As deployments grow, split them into modules — separate .bicep files called from a main template. A module encapsulates a piece of infrastructure (a network, a database) with its own params and outputs, and you wire modules together by passing one’s outputs into another.

Parameter files (.bicepparam or JSON) supply environment-specific values, so the same template deploys dev and prod. Decorators add validation: @minLength, @allowed, @secure (for passwords). This keeps templates reusable, validated, and DRY.

🌍Real-World Example
// main.bicep
@allowed(['dev', 'prod'])
param env string

module network './modules/network.bicep' = {
  name: 'network'
  params: { env: env }
}

module app './modules/app.bicep' = {
  name: 'app'
  params: { subnetId: network.outputs.subnetId }
}
az deployment group create -g rg -f main.bicep -p main.bicepparam
✍️Hands-On Exercise
  1. Split a template into a network module and an app module that consumes its output.
  2. Add an @allowed decorator restricting an environment parameter.
  3. Mark a password parameter @secure and explain why.
  4. Describe how a parameter file enables dev vs prod from one template.
🧾Cheat Sheet
FeatureSyntax
Module callmodule x './x.bicep' = { params: {…} }
Module outputx.outputs.value
Param file.bicepparam / JSON
Allowed values@allowed([…])
Length validation@minLength / @maxLength
Secret param@secure()
💬Common Interview Questions
How do Bicep modules pass data between each other?

A module exposes outputs; you reference them (e.g. network.outputs.subnetId) and pass them as params into another module, which also wires up deployment order.

What does the @secure() decorator do?

It marks a parameter (like a password) as sensitive so its value is excluded from deployment logs and output history.

📚Official Documentation

📝 My notes on this topic

Auto-saves as you type