Parameters in Bicep
What you'll learn: How to define reusable, validated parameters in Bicep using decorators to make your infrastructure templates flexible and self-documenting.
What Are Parameters in Bicep?
Parameters let you customize your Bicep deployments without hardcoding values. Think of them like function arguments—you define what inputs your template expects, then supply actual values at deployment time. This makes a single template work for dev, staging, and production environments.
Defining Parameters with Decorators
In Bicep, you declare parameters using the param keyword. What makes Bicep powerful are decorators—special annotations (prefixed with @) that add validation rules, documentation, and constraints:
@description('The name of the storage account')
@minLength(3)
@maxLength(24)
param storageAccountName string
@description('The Azure region for resources')
@allowed([
'eastus'
'westus'
'centralus'
])
param location string = 'eastus'
@description('Number of VM instances to create')
@minValue(1)
@maxValue(10)
param instanceCount int = 2
How Decorators Work
@description: Documents what the parameter does (shows up in tooling)@minLength/@maxLength: Validates string length@allowed: Restricts values to a specific list (like an enum)@minValue/@maxValue: Sets numeric boundaries- Default values: Use
= valueafter the type
These decorators catch errors before deployment, giving you immediate feedback if someone tries to deploy with invalid values.
Using Parameters
Once defined, reference parameters by name in your resource declarations—just like you did in ARM templates, but cleaner:
resource storageAccount 'Microsoft.Storage/storageAccounts@2021-02-01' = {
name: storageAccountName
location: location
}
Key Takeaway: Bicep parameters with decorators provide type safety, built-in validation, and self-documentation, making your infrastructure templates reusable, maintainable, and error-resistant.